Comment on the output of this C code?
#include
void main()
{
int k = 4;
int *const p = &k;
int r = 3;
p = &r;
printf("%d", p);
}
Answer: C
Since the pointer p is declared to be constant, trying to assign it with a new value results in an error.
Output:
$ cc pgm11.c
pgm11.c: In function ‘main’:
pgm11.c:7: error: assignment of read-only variable ‘p’
pgm11.c:8: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int * const’