What is the output of the following C program?
#include <stdio.h>
int main(void) {
int x = 5, y = 7;
const int *p = &x;
x = 6;
printf("%d ", *p);
p = &y;
printf("%d\n", *p);
return 0;
}
x itself is not const, so x = 6 is fine and *p sees it. "Pointer to const" only forbids writing through p; p itself may also move to y.