ProgrammingHard
struct P { int a[3]; }; struct P p = {{1, 2, 3}}; struct P *q = &p; printf("%d", *(q->a + 2)); What is printed?
- A. 3
- B. 2
- C. 1
- D. 0
Correct answer: A. 3
q->a decays to a pointer to the first int, and adding 2 reaches the third element, which is 3.
More C Programming questions
- char words[] = {"ab", "cd", "ef"}; char pp = words + 1; printf("%s", pp + 1); What is printed?
- int a[] = {10, 20, 30}; int p = a; p++; printf("%d", p + p[1]); What is printed?
- int x = 1, y = 2; int p = &x, pp = &p; pp = &y; printf("%d %d", x, p); What is printed?
- int inc(int n) { return n + 1; } int dbl(int n) { return n 2; } int (f[2])(int) = {inc, dbl}; printf("%d", f[1](f[0](3))); What is printed?
- int x = 2; switch (x) { case 2: x += 1; case 3: x += 10; break; default: x = 0; } printf("%d", x); What is printed?
- int p = (int[]){4, 5, 6}; printf("%d", p[2]); What is printed?