ProgrammingEasyTCS NQT · Infosys pattern

What is printed?

What is printed?
int arr[] = {10, 20, 30, 40};
int *p = arr;
p += 2;
printf("%d", *p);
  1. A. 40
  2. B. 30
  3. C. 12
  4. D. 20

Correct answer: B. 30

Pointer arithmetic moves in units of the pointed-to type: p += 2 moves two ints ahead, to arr[2], which is 30. It does not add 2 bytes or 2 to the value.

More C Programming questions

Exams that ask this topic