ProgrammingModerateTCS NQT · Infosys
int x = 0x1F; What does printf("%d", 07 + 0x1F) print?
- A. 26
- B. 0x26
- C. 38
- D. 24
Correct answer: C. 38
07 is octal for 7 and 0x1F is 31 in hexadecimal, so the sum is 38. A leading zero makes a constant octal, which catches many readers.
More C Programming questions
- uint32t x = 0xFFFFFFFFu; How many times does while (x > 0) x >>= 1; execute its body, counting from the start?
- int cnt[3] = {0}; int p; for (p = cnt; p < cnt + 3; p++) p = p - cnt; What is the sum of cnt[0] + cnt[1] + cnt[2]?
- A loop while (!(x & 1)) { x >>= 1; c++; } counts the trailing zero bits of a nonzero uint32t x = 0b101000. What is c?
- uint64t mask = (1ULL << 40) - 1; What is mask?
- int a[] = {3, 1, 2}; qsort(a, 3, sizeof(int), cmp) sorts ascending, where cmp compares with (x > y) - (x < y). Then What is a[0]100 +…
- A program must answer 10^5 range-sum queries on an array of 10^5 ints within a 1 second limit. Which approach is fast enough?