C dereferencing pointer



Dereferencing Pointer in C Programming Language :

  1. Asterisk(*) indirection operator is used along with pointer variable while Dereferencing the pointer variable.
  2. Asterisk Operator is also called as value at operator
  3. When used with Pointer variable, it refers to variable being pointed to,this is called as Dereferencing of Pointers

What is Dereferencing Pointer ?

[box]

  1. Dereferencing Operation is performed to access or manipulate data contained in memory location pointed to by a pointer
  2. Any Operation performed on the de-referenced pointer directly affects the value of variable it pointes to.

[/box]

Live Example : Dereferencing Pointer

// Sample Code for Dereferencing of Pointer
int n = 50 , x ;

int *ptr ; // Un-initialized Pointer

ptr = &n; // Stores address of n in ptr

x = *ptr; // Put Value at ptr in x

Evaluation :

// Sample Code for Dereferencing of Pointer

*(ptr) = value at (ptr)
       = value at (2001) 
       = 50

//Address in ptr is nothing but address of n

Summary :

  1. Name of Normal Variable always points to the Value  of variable
  2. Pointer variable always Stores Address of variable
  3. *ptr and  num will give us same value.

Variable and Address of Memory Location

Variable Value in it
num 50
&num 1002
ptr 1002
*ptr 50

In the next chapter we will be learning the void pointers. Void Pointer is special type of pointer which can store the address of any variable.