Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

C | Storage Classes and Type Qualifiers | Question 19

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article




#include <stdio.h>
int main()
{
    int x = 5;
    int const * ptr = &x;
    ++(*ptr);
    printf("%d", x);
    
    return 0;
}

(A) Compiler Error
(B) Runtime Error
(C) 6
(D) 5


Answer: (A)

Explanation: See following declarations to know the difference between constant pointer and a pointer to a constant.
int * const ptr —> ptr is constant pointer. You can change the value at the location pointed by pointer p, but you can not change p to point to other location.
int const * ptr —> ptr is a pointer to a constant. You can change ptr to point other variable. But you cannot change the value pointed by ptr.

In the above program, ptr is a pointer to a constant. So the value pointed cannot be changed.


Quiz of this Question

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads