Question
Comment on the output of this C code?
int main()
{
const int i = 10;
int *ptr = &i;
*ptr = 20;
printf("%d\n", i);
return 0;
}
int main()
{
const int i = 10;
int *ptr = &i;
*ptr = 20;
printf("%d\n", i);
return 0;
}
Answer: Option B
Was this answer helpful ?
Changing const variable through non-constant pointers invokes compiler warning
Output:
$ cc pgm2.c
pgm2.c: In function 'main':
pgm2.c:5: warning: initialization discards qualifiers from pointer target type
$ a.out
20
Was this answer helpful ?
Submit Solution