ProgrammingHardTCS NQT · Infosys
struct P { int x, y; } arr[4]; struct P *p = arr; p += 2; What is p - arr?
- A. 2
- B. 4
- C. 8
- D. 1
Correct answer: A. 2
p += 2 moves two struct elements, not two ints, so p - arr is 2. Pointer arithmetic counts whole objects of the pointed-to type.
More C Programming questions
- #define MIN(a,b) ((a)<(b)?(a):(b)). What does printf("%d", MIN(MIN(3,1),2)) print?
- int x = 5; printf("%d", x > 3 ? x - 3 : x + 3); What is printed?
- What does printf("%d", (4, 5) 2) print?
- int x = 0, y = 1; What does printf("%d", !x == y) print?
- printf("%d %d", 1 < 2 < 3, 3 > 2 > 1); What is printed?
- What does printf("%d", -5 % 3) print?