ProgrammingHardHCL · Tech Mahindra pattern

What is printed? const qualifies what p points to, not p itself.

What is printed? `const` qualifies what `p` points to, not `p` itself.
int x = 5, y = 10;
const int *p = &x;
p = &y;
printf("%d", *p);
  1. A. 10
  2. B. 5
  3. C. Compilation error: cannot reassign p
  4. D. Compilation error: cannot read *p

Correct answer: A. 10

const int *p means the pointed-to int cannot be modified through p (*p = ... would be an error), but p itself is an ordinary variable and can be repointed freely. p = &y is legal, so *p reads y = 10.

More C Programming questions

Exams that ask this topic