C | Data Types | Question 7

Assume that the size of char is 1 byte and negatives are stored in 2’s complement form

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(A) 135
(B) +INF
(C) -121
(D) -8


Answer: (C)

Explanation: 125 is represented as 01111101 in binary and when we add 10 i.e 1010 in binary it becomes : 10000111. Now what does this number represent?
Firstly, you should know that char can store numbers only -128 to 127 since the most significant bit is kept for sign bit. Therefore 10000111 represents a negative number. To check which number it represents we find the 2’s complement of it and get 01111001 which is = 121 in decimal system. Hence, the number 10000111 represents -121.

Quiz of this Question



My Personal Notes arrow_drop_up

Improved By : shaztri



Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.