comment on the following? const int *ptr;

2025

comment on the following?

const int *ptr;

Answer: A. you cannot change the value pointed by ptrThe declaration const int *ptr means the value pointed to by ptr is constant. This means you cannot modify the integer value through ptr. However, the pointer…

  1. A.

    you cannot change the value pointed by ptr

  2. B.

    you can change the value of the pointer

  3. C.

    none of these

  4. D.

    you can change the pointer as well as value pointing by it

Attempted by 392 students.

Show answer & explanation

Correct answer: A

The declaration const int *ptr means the value pointed to by ptr is constant. This means you cannot modify the integer value through ptr. However, the pointer variable itself can be reassigned to point to a different memory location. The const applies to the data type being pointed to, not the pointer variable.

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…