133k views
4 votes
Comment on the following?int * const ptr;A. You cannot change the value pointed by ptrB. You cannot change the pointer ptr itselfC. Both (a) and (b)D. You can change the pointer as well as the value pointed by itComment on the following?const int * const ptr;A. You cannot change the value pointed by ptrB. You cannot change the pointer ptr itselfC. Both (a) and (b)D. You can change the pointer as well as the value pointed by it

1 Answer

3 votes

For the first question, the correct answer is C. The declaration "int * const ptr" means that the pointer variable "ptr" is a constant pointer to an integer, which means that you cannot change the value pointed by ptr (option A) and you cannot change the pointer ptr itself (option B).

For the second question, the correct answer is A. The declaration "const int * const ptr" means that the pointer variable "ptr" is a constant pointer to a constant integer, which means that you cannot change the value pointed by ptr (option A) and you cannot change the pointer ptr itself (option B).

User Slm
by
8.5k points