C | Data Types | Question 7
Assume that the size of char is 1 byte and negatives are stored in 2’s complement form
#include<stdio.h> int main() { char c = 125; c = c+10; printf("%d", c); return 0; } |
chevron_right
filter_none
(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
Recommended Posts:
- C | Data Types | Question 4
- C | Data Types | Question 8
- C | Data Types | Question 6
- C | Data Types | Question 9
- C | Data Types | Question 3
- C | Data Types | Question 5
- C | Data Types | Question 1
- C | Data Types | Question 2
- Java | Data Types | Question 3
- Java | Data Types | Question 2
- Java | Data Types | Question 1
- Data Types in C
- Uninitialized primitive data types in C/C++
- How to print range of basic data types without any library function and constant in C?
- int (1 sign bit + 31 data bits) keyword in C
Improved By : shaztri

