Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What does “dereferencing” a pointer mean?

Please include an example with the reason.
by

2 Answers

akshay1995
Dereferencing a pointer means getting the value that is stored in the memory location pointed by the pointer. The operator is used to do this, and is called the dereferencing operator.

int a = 10;
int* ptr = &a;

printf("%d", *ptr); // With *ptr I'm dereferencing the pointer.
// Which means, I am asking the value pointed at by the pointer.
// ptr is pointing to the location in memory of the variable a.
// In a's location, we have 10. So, dereferencing gives this value.

// Since we have indirect control over a's location, we can modify its content using the pointer. This is an indirect way to access a.

ptr = 20; // Now a's content is no longer 10, and has been modified to 20.
sandhya6gczb
Dereferencing a pointer means pointing to an element which is a pointer holding the address of the actual value.

int main() {
int a = 7, b ;
int p;
p = &a; // Has address of a
b =
p; // pointer pointing to some another pointer
}

Login / Signup to Answer the Question.