+ 1
Why output is 9 ? Explain please
#include <stdio.h> int main() { char c = 255; c=c+10; printf("%d",c); return 0; }
5 Answers
+ 5
As you used %d so c will be converted into number which will be -1 so c = -1 + 10 = 9
If you want to see then print this:
cout << (int) c; // this will give -1
+ 4
saurav
Read this thread:
https://stackoverflow.com/questions/10264344/why-stores-255-in-a-char-variable-give-its-value-1-in-c#:~:text=The%20value%20255%20cannot%20be,bit%2Dpattern%20of%20%2D1%20.
+ 2
Because char is 8bit and can hold a maximum of 255 (1111 1111)binary so adding 1 to it caused it to over flow like (1 0000 0000)b and the most significant bit is trimmed so adding the remaining 9 it becomes 0+9 =9
0
A͢J Why -1 ?
0
saurav learn about ASCII value and type conversion, you'll get your answer.