Which code snippet increments the integer value pointed to by p, without changing the pointer itself?

Enhance your programming skills with the RECF Programming Test. Features flashcards and multiple choice questions with hints and explanations. Prepare for success!

Multiple Choice

Which code snippet increments the integer value pointed to by p, without changing the pointer itself?

Explanation:
You modify the value at the address the pointer holds, not the pointer itself. Dereferencing a pointer to int gives you that int in memory, so applying the post-increment to the dereferenced value increments the actual integer stored there while leaving the pointer’s address unchanged. That exact behavior—incrementing the pointed-to value without moving the pointer—matches the requirement. Incrementing the pointer would move it to the next int in memory, not affect the current value. Using a non-pointer parameter would not compile for dereferencing. Decrementing would reduce the value instead of increasing it.

You modify the value at the address the pointer holds, not the pointer itself. Dereferencing a pointer to int gives you that int in memory, so applying the post-increment to the dereferenced value increments the actual integer stored there while leaving the pointer’s address unchanged. That exact behavior—incrementing the pointed-to value without moving the pointer—matches the requirement.

Incrementing the pointer would move it to the next int in memory, not affect the current value. Using a non-pointer parameter would not compile for dereferencing. Decrementing would reduce the value instead of increasing it.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy