Created: 2023-01-12 20:23
Status: #concept
Subject: Programming
Tags: C Memory Address Pointer Address Operator

Dereference

The Dereference Operator * allows the accessing of the data pointed by a Pointer.

Not to be confused with Pointer Variable declaration.

C Syntax

int num;
int *p = # // gets the address of {num} and assigns it to pointer {p}

printf("%d", *p); // prints the value pointed by {p}
printf("%d", *(&num)); // prints the value pointed by the memory address of {num}
It is the inverse Operator of Address Operator &, so they cancel out.

Different Contexts, Different Meaning

The * operator has different meanings depending on;

  • whether we are using it to declare a pointer variable
  • we are using it to dereference a pointer variable

int *p = &i; // declare an int pointer and assign the address of i to it
*p = &i; // dereference p and assign the address of i to it

References