Comment on the following?
const int *ptr;
A. We cannot change the value pointed by ptr.
B. We cannot change the pointer ptr itself.
C. Both of the above
D. We can change the pointer as well as the value pointed by it.
Answer: Option A
Solution(By Examveda Team)
int * : pointer to intint const * : pointer to const int
int * const : const pointer to int
int const * const : const pointer to const int
Now the first const can be on either side of the type so:
const int * == int const *
const int * const == int const * const
So the above declaration is pointer to const int. Which means,we cannot change the value pointed by ptr.
Join The Discussion
Comments ( 3 )
Related Questions on Pointer
In C, what is a pointer primarily used for?
A. Decision making
B. Code organization
C. Variable declaration
D. Storing values
In C, how do you declare a pointer variable that can store the address of an integer?
A. int *ptr;
B. ptr int;
C. int ptr;
D. ptr *int;
What is the purpose of the '->' operator in C when used with pointers?
A. Arithmetic operation
B. Indirection operator
C. Member access operator
D. Bitwise operation
I do not think that it will not allow changing the value of a variable whose address will be stored in a constant pointer.
int const * : Point a constant int so its can not be changed.
please provide explanation for this question