Pointers and dereferencing in C: which operator retrieves the value stored at the memory address contained in a pointer variable?

Difficulty: Easy

Correct Answer:

Explanation:


Introduction / Context:
Pointers store memory addresses, and dereferencing a pointer accesses the object at that address. This is central to dynamic memory, arrays, and function parameters. Knowing the distinct roles of the unary * and & operators avoids confusion when reading and writing pointer code.



Given Data / Assumptions:

  • We have a pointer variable p that holds the address of some object.
  • Standard C operator meanings are assumed.


Concept / Approach:
The unary * operator is the dereference operator. Applied to a pointer p, the expression *p yields the lvalue of the object pointed to. Conversely, & is the address-of operator that produces a pointer from an object. The tokens && and || are logical operators for boolean conditions and have nothing to do with pointer access.



Step-by-Step Solution:
Given int x = 10; int *p = &x; the expression *p evaluates to 10.Assignments through pointers use dereference: *p = 42; changes x to 42.Therefore, the operator that “gets the value at the address” in a pointer is *.



Verification / Alternative check:
Print *p and x after assignments to confirm they remain in sync because they refer to the same object via direct and indirect access.



Why Other Options Are Wrong:

  • & obtains an address; it does not access the value through a pointer.
  • && and || are logical operators for conditions, unrelated to memory access.


Common Pitfalls:
Confusing * in declarations (type name) with * in expressions (dereference); both are related but occur in different grammatical contexts.



Final Answer:
.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion