ProgrammingVery hardGATE CS · Campus placements
Which of these statements are well defined by the C standard? I. uint8_t x = 255; x = x + 1; leaves x equal to 0. II. int a = INT_MAX; a + 1 yields INT_MIN. III. unsigned int u = 0; u - 1 equals UINT_MAX. IV. sizeof(char) equals 1.
- A. I and III only
- B. I, III and IV only
- C. II and IV only
- D. I, II, III and IV
Correct answer: B. I, III and IV only
I, III and IV are defined: unsigned wraparound is modular, and sizeof(char) is 1 by definition. II is signed overflow, which is undefined behaviour, so no answer that includes it can be right.
More C Programming questions
- What is the sum of the decimal digits of 2^20 = 1048576?
- uint16t a = 40000, b = 40000; uint32t s = a + b; What is s?
- uint32t x = 0x80000001u; x = (x << 1) | (x >> 31); What is x?
- unsigned char c = 0x7F; c = c 2 + 2; What is c?
- For the array {4, 1, 3}, how many index pairs i < j have a[i] > a[j]? These pairs are called inversions.
- How many binary strings of length 5 contain no two adjacent 1s?