What will be the output of the following C code?#include <stdio.h> int main() { signed char chr; chr = 128; printf("%d\n", chr); return 0; }a.-128b.128c.Depends on the compilerd.Compiler Error
Question
What will be the output of the following C code?#include <stdio.h> int main() { signed char chr; chr = 128; printf("%d\n", chr); return 0; }a.-128b.128c.Depends on the compilerd.Compiler Error
Solution
The output of the given C code will be -128.
Here's why:
In C, the range of values that can be represented by a signed char is from -128 to 127. When you try to assign a value of 128 to a signed char, it overflows and wraps around to the beginning of the range, which is -128. So, the output of the code will be -128.
Therefore, the correct answer is a. -128.
Similar Questions
what will be the output of the c program?
What will be the output of the following code?
What will be the output of the following C++ code?
What will be the output of the following program?
What will be the output of the following C code?#include <stdio.h>int main() { int i; for (i = 0; i < 5; i++); printf("%d\n", i); return 0;}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.