ProgrammingHardTCS NQT · Infosys
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. 2
- B. 3
- C. 6
- D. 0
Correct answer: B. 3
p - cnt is the element index, so cnt becomes {0, 1, 2}. The sum is 3.
More C Programming questions
- 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?
- Using fast exponentiation with reduction modulo 1000000007 after each multiplication, what is 2^100 mod 1000000007?
- int n = -1; uint64t u = (uint64t)n; What is u?