How dereferencing work?

Whenever we ask the compiler to dereference a pointer, it does three things:

  • It first looks up the address stored in the pointer.
  • Then it looks for the type of pointer so that it can deduce the amount of memory to read. For example, 4 byes for int, 1 byte for char, etc. It is also the main reason why we need to specify the pointer type in the declaration even though the size of every pointer in a system is the same.
  • Finally, it reads the memory and returns the data stored.

Note: From the above reasoning, we can also infer that we cannot dereference the void pointer as the size of the data it is pointing to is unknown. So we need to typecast the void pointer to dereference it.



Dereference Pointer in C

We know that the pointer variable can store the memory address in C language and in this article, we will learn how to use that pointer to access the data stored in the memory location pointed by the pointer.

Similar Reads

What is a Pointer?

First of all, we revise what is a pointer. A pointer is a variable that stores the memory address of another variable. The pointer helps us to manipulate the data in the memory address that the pointer points. Moreover, multiple pointers can point to the same memory....

Dereference Pointer in C

Accessing or manipulating the content that is stored in the memory address pointed by the pointer using dereferencing or indirection operator (*) is called dereferencing the pointer....

Examples of Pointer Dereferencing

Example 1:...

How dereferencing work?

...