ProgrammingHardTCS NQT · Infosys
int a[] = {1, 2, 3, 4, 5}; int *p = a; p += 3; printf("%d", *p--); What is printed?
- A. 3
- B. 4
- C. 5
- D. 2
Correct answer: B. 4
After p += 3 it points at a[3] = 4. The postfix decrement uses the old value, so 4 is printed and p moves back to a[2].
More C Programming questions
- int x = 10; int px = &x; px += px 2; What is x?
- What is ~0u / 2 + 1 for a 32-bit unsigned int?
- What does (unsigned int)(-1) % 10 evaluate to on a platform with a 32-bit unsigned int?
- How many ways are there to write 5 as an unordered sum of 1s and 2s?
- void rev(char s) { char e = s + strlen(s) - 1; while (s < e) { char t = s; s++ = e; e-- = t; } } After rev("abcde") runs on a writable…
- Which algorithm finds the maximum subarray sum of an array of n = 10^6 ints in time within a typical 1 second contest limit?