ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
int a[] = {1,2,3,4,5};
int *p = a + 3;
int *q = a;
printf("%d %d %d", p - q, *p-- , *p);
  1. A. 3 4 4
  2. B. 3 4 3
  3. C. 3 3 2
  4. D. 2 4 3

Correct answer: B. 3 4 3

p - q = 3 (element distance). *p-- uses p's current value first (a[3]=4), then decrements p to point at a[2]. The next *p reads a[2]=3. Output: 3 4 3.

More C Programming questions

Exams that ask this topic