C | Storage Classes and Type Qualifiers | Question 17

Output?

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
  
int main(void)
{
    int i = 10;
    const int *ptr = &i;
    *ptr = 100;
    printf("i = %d\n", i);
    return 0;
}

chevron_right


(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



My Personal Notes arrow_drop_up