in Programming edited by
385 views
7 votes
7 votes

What is the output of the following code snippet?  

#include <stdio.h>
int main()
{
char c=125;
c=c+10;
printf("%d",c);
return 0;
}

 

in Programming edited by
by
385 views

2 Answers

17 votes
17 votes
Best answer

Char is of 1 Byte

range of singed char = {-2^n -1 to +2^n-1} = -128 to +127

char c =125

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
selected by

1 comment

Opsss.... silly question....
0
0
8 votes
8 votes
(125= 01111101) + (10=00001010) = 10000111... showing overflow as addition of two positive numbers giving negative result.
Content of register = 10000111= -121 ( -2^7 + 7)

1 comment

Nice :)
1
1
Answer:

Related questions