Which of the following statements is INCORRECT with respect to pointers…

2017

Which of the following statements is INCORRECT with respect to pointers declared in the following ‘C’ code?

void main()

{

int a[10], *p, *q;

p = &a[5];

q = &a[7];

}

  1. A.

    q-p

  2. B.

    p+1

  3. C.

    q-3

  4. D.

    p+q

Attempted by 304 students.

Show answer & explanation

Correct answer: D

In C, pointer arithmetic allows subtracting two pointers (q - p) or adding/subtracting an integer to/from a pointer (p + 1, q - 3). However, adding two pointers (p + q) is geometrically meaningless and syntactically invalid because it results in an illegal memory address, causing a compilation error.

Thus, the incorrect statement (correct option) is D.

Explore the full course: Coal India Management Trainee