Discussion :: C-MCQs
-
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;
}
Answer : Option B
Explanation :
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
Be The First To Comment