In this article Address Operator in C we give the information about The Address operator (&) and indirection operator (*) are the most important concepts to understand pointer because when we use pointer in C language, both these concepts will be used.

Address Operator (&) In C

When we declare a variable in C language, then by looking at that variable we can easily tell these three things – name of the variable, what type of value will be stored in the variable and what size value will be stored in the variable. But there is one more thing that the variable gets in the memory and that is the memory address.

The place where the variable gets memory has an address which is called memory address. The memory address given to the variable is not in our hands, it is decided by the system.

If we want to know the memory address of any variable, then for this we have to use address operator (&).

Address (&) is an operator that provides the address of a variable. It is a unary operator which acts on only one operand. This operand can only be a variable name, we cannot use it with a constant value.

We can easily identify that variable by the variable address provided by Address Operator (&). Address Operator (&) is also called referencing operator.

Syntax -:

&variable_name;

Example -:

#include<stdio.h>

void main()

{

  int p = 15;

  printf(” %d \n “, p );

  printf(“%d \n”, &p);

}

In this example we have int p = 15; By declaring a variable named p and at the time of declaration, 15 was also assigned to that variable. After this, with the help of printf() function, we first printed the value of p and printed the memory address of the location where the p variable got the memory, the output of which was something like this.

Output -:

15

5000

Asterisk (*) or Indirection Operator In C

Asterisk (*) is an operator that assigns a stored value to a variable address. It is a unary operator that acts on only one operand. Indirection operator (*) takes the address of the variable as an argument. It is also called dereferencing operator.

Syntax -:

*&variable_name;

Example -:

#include<stdio.h>

void main()

{

int x =15;

int y = *&x;

printf(” y = %d “, y);

}

In this example we have int x = 5; By declaring a variable named x and at the time of declaration, 5 was also assigned to that variable. After this we created another int variable named y and in this y variable *&x; By doing this, whatever value is in the address of x variable is assigned to the y variable. Here *x returns the value stored in the address of the variable.

With the help of printf() function, we first assigned it to the y variable and printed the value on the screen, the output of which was something like this.

Output -: y = 15

Example of Address Operator (&) and indirection Operator

#include<stdio.h>

void main()

{

  int x = 15;

  printf(” %d \n “, x );

  printf(“%d \n”, &x);

  printf(” %d ” *&x);

}

Output -:

15

5000

15

In this example we created a variable named x and assigned 15 to it, after that with the help of first printf() we print the value stored in x variable and with the help of second printf() we print the address of x variable Screen printed.

In the third printf, we passed the address of x variable as argument by *&x in indirection operator (*) and as we know that when passing the address of a variable in indirection operator (*), indirection operator (* ) returns the value stored in that variable address so with the help of third printf we got 15 value as output.

Some More: 

POP- Introduction to Programming Using ‘C’

DS – Data structure Using C

OOP – Object Oriented Programming 

Java Programming

DBMS – Database Management System

RDBMS – Relational Database Management System

Join Now: Data Warehousing and Data Mining 

Leave a Reply

Your email address will not be published. Required fields are marked *