ProgrammingHardGATE CS · TCS NQT

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int x = 1, y = 2;
    const int *cp = &x;
    int *const pc = &y;
    *pc = 5;
    printf("%d %d", *cp, y);
}
  1. A. 5 2
  2. B. 1 2
  3. C. 5 5
  4. D. 1 5

Correct answer: D. 1 5

cp points at x and is never changed, while pc points at y, which the assignment *pc = 5 changes. The pointer itself is constant, but the int it points to is not.

More C Programming questions

Exams that ask this topic