ProgrammingModerate
int a[] = {10, 20, 30}; int *p = a; p++; printf("%d", *p + p[1]); What is printed?
- A. 40
- B. 60
- C. 50
- D. 30
Correct answer: C. 50
After p++, p points at a[1], so *p = 20 and p[1] = *(p + 1) = a[2] = 30, total 50. 30 forgets that p moved (10 + 20), and 40 adds 20 twice.
More C Programming questions
- 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?
- int s = 0; for (int i = 0, j = 5; i < j; i++, j--) s += i j; printf("%d", s); What is printed?
- char s[][4] = {"ab", "xyz"}; printf("%zu", sizeof s); What is printed?