C Programming :: Declarations and Initializations - Discussion
11 / 54
#include <stdio.h>
void main(){
char c=125;
c=c+10;
printf("%d",c);
}
#include <stdio.h>
void main(){
char c=125;
c=c+10;
printf("%d",c);
}
A135
BINF
C-121
DCompilation Error
Show 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
Asked In ::
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
Read Full Answer
Report Error
Please Login First Click Here
As we know char data type shows cyclic properties i.e. if you will increase or decrease the char variables beyond its maximum or minimum value respectively it will repeat same value according to following cyclic order:
So,
125+1= 126
125+2= 127
125+3=-128
125+4=-127
125+5=-126
125+6=-125
125+7=-124
125+8=-123
125+9=-122
125+10=-121
Read Full Answer
Report Error
Please Login First Click Here
Here c is initialized as char, and the valid range of char is from -128 to +127. If, as a result of incrementation, the value of c becomes 128, the range gets exceeded, and the first number from the negative side of the range gets assigned to c(i.e., -128).
Therefore,
125+1=126
125+2=127
125+3=-128
125+4=-127
.
.
.
125+9=-122
125+10=-121
Hence, the correct option is option C.
Read Full Answer
Report Error
Please Login First Click Here