What will the output of the following C code be? #include stdio.h> const int I = 10; int *ptr = I *ptr = 20; printf(" percent dn", I return 0;
A. Compile time error
B. Compile time warning and printf show 20
C. Undefined behaviour
D. 10
Answer:B
What will the output of the following C code be? #include stdio.h> const int I = 10; int *ptr = I *ptr = 20; printf(" percent dn", I return 0;
A. Compile time error B. Compile time warning and printf show 20 C. Undefined behaviour D. 10
Explanation: Changing a const variable with non-constant pointers generates a 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