C | Storage Classes and Type Qualifiers | Question 17
Output?
#include <stdio.h> int main( void ) { int i = 10; const int *ptr = &i; *ptr = 100; printf ( "i = %d\n" , i); return 0; } |
(A) i = 100
(B) i = 10
(C) Compiler Error
(D) Runtime Error
Answer: (C)
Explanation: Note that ptr is a pointer to a constant. So value pointed cannot be changed using the pointer ptr. See Const Qualifier in C for more details.
Quiz of this Question