C Programming :: Declarations and Initializations

1. What is the output of the following 'C' program ?

void main(){
char c=125;
c=c+10;
printf("%d",c);
}

Answer: Option C

Explanation :

Here char is signed so,the size of char is 1 bytes and its value range are -128 to 127,



and it will be something like below



-128 -127 -126 .......... 0 ....... 126 127 in the cycle. 



Now as per questions c = 125 it is under the above limit.



but when 10 added to it, it becomes 125 10 = 135



125 126 127 -128 -127 -126 -125 -124 -123 -122 -121 



So, count above 135 will fall at -121, so Answer will be -121



If in the question it would have given unsigned char then answer will be 135

Post Your Answer Here:     

Reply     |    Rate This: +2 -0      |     Report     |     To Reading List



Report Error

Please Login First Click Here

Reply     |    Rate This: +2 -0      |     Report     |     To Reading List



Report Error

Please Login First Click Here

Reply     |    Rate This: +0 -0      |     Report     |     To Reading List



Report Error

Please Login First Click Here

Reply     |    Rate This: +0 -0      |     Report     |     To Reading List



Report Error

Please Login First Click Here