Join Regular Classroom : Visit ClassroomTech

Dereferencing / Indirection operator in C

In computer programming dereferencing operator also known as indirection operator. It is used to represent a pointer. This dereferencing operator is denoted by an asterisk (*). Pointer variable stores the address of the variable it is pointing to. When a dereferencing operator is used then it returns the value of the variable it is pointing to.

Why Pointers are called Dereferencing Operator?

Dereferencing means to access or manipulate values stored any memory locations. Often in programming languages like C/C++ we use pointers to access the value at some memory locations. It points to some variable where the data or value is stored (Indirection Operator).

Usage of dereferencing operator:

1. Dereferencing operator / Pointer is used to manipulate or access the data stored in the memory location.

2. The operations made on dereferenced pointer will also affect the value of the variable pointed by the pointer.

Example

/* C program for explaining Dereferencing Operators */
/* www.codewindow.in */

#include <stdio.h>

// Driver code
int main() {
	int x=5;
	int *ptr;
	
	ptr=&x;
	*ptr=7;
	printf("Value of the variable is %d", x);
	
	return 0;
}

Output

Value of the variable is 7

Explanation
Let’s break the above program line by line:

1. At first the variable to be pointed and the pointer is declared. (int x=5; int *ptr;)

2. Thereafter, the address of the variable is stored in the pointer variable (ptr=&x;)

3. The value of the variable can be manipulated by the dereferenced pointer (*ptr=7;)


Follow Us


You Missed

Also Checkout