Practice mode C Language

In the declaration int *const p = &x;, what is constant?

Correct answer A. The pointer p itself, which cannot be made to point elsewhere

Explanation

Read the declaration from the name outwards: p is a const pointer to int. const after the * applies to the pointer, so p = &y is an error, but *p = 5 is allowed. In const int *p the const is before the *, so the int is read-only through p while p can be reassigned. const int *const p makes both constant.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.