ProgrammingHardTCS NQT · Infosys
unsigned char c = 0x7F; c = c * 2 + 2; What is c?
- A. 0
- B. 2
- C. 256
- D. 255
Correct answer: A. 0
c * 2 + 2 is 256 in int, and storing 256 into an unsigned char keeps 256 mod 256 = 0. The assignment is well defined.
More C Programming questions
- 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?
- char s[] = "abc"; s[0] = 'x'; printf("%s", s); prints what?
- unsigned int n = 1u; unsigned int r = n << 31; What is r?
- int a = -7, b = 2; What is a / b b + a % b?
- int m[2][2] = {{1, 2}, {3, 4}}; int (r)[2] = m; What is r[1][0] + (r[0] + 1)?