main()
{
char c;
int i = 456;
clrscr();
c = i;
printf("%d", c);
}
A) none of the above
B) random number
C) -456
D) 456
Explanation: Answer is -56
See.........
converting 456 to binary we get 111001000.
it takes more than one byte. Se when we assign c i the most significant will be lost. Then the value of c is 11001000. when you print the value of c using d(signed integer) the most significat bit will be considered as the +/-. Here it is 1 and hence the number is negative. Negative numbers are in 2's compliment form. so converting back we will get 00111000. ie -56 in decimal. if you used u instead of d you could have got 200.
Monday, August 17, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment