Explanation of Address Operator in C

Explanation of Address Operator in C
Techiio-author
Written by Shuvhojit DebFebruary 9, 2022
6 min read
C
2 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 2 VIEWS SHARE
Techiio-author
Shuvhojit Deb

Full Stack Developer

In this article, you can learn about the address operators in C.

Introduction:

The Address Operator in C is also called a pointer. This address driver is denoted by “&”. This & symbol is called an ampersand. This & is used in a unary driver. The purpose of this address driver or pointer is used to return the address of the variable. Once we declared a pointer variable, we've to initialize the pointer with a valid memory address; to get the memory address of the variable ampersand is used. When we use the ampersand symbol as a prefix to the variable name & and it gives the address of that variable. An address of the driver is used within C that's returned to the memory address of a variable. These addresses returned by the address of the driver are known as pointers because they “point” to the variable in memory.

What are the usages of it:

  1. While scanning the user input, we used the ampersand operator.
  2. While displaying the address of the variable we used the ampersand operator.

Reason for Address Operator used in C:

Address operators are commonly used for 2 purposes:

  • Conduct parameter passing by reference such as name.
  • Establish pointer values and address of operator’s point to the memory location because the value of the pointer is the memory location or memory address. The data item is saved in memory.

Address Operators:

There are two important operators which are highly required if you are working with the pointers. Without these operators, we cannot work with the pointers.

The operators are:-

  1. The * Operator (Dereference Operator or Indirection Operator)
  2. The & Operator (Address of Operator)

1. The * Operator (Dereference Operator or Indirection Operator) -

"Dereference Operator" or "Indirection Operator denoted by an asterisk character (*), * is a unary operator which performs two operations with the pointer (which is used for two purposes with the pointers).

A) To declare a pointer

B) To access the stored value of the memory (location) pointed by the pointer

A) To declare a pointer -

Consider the syntax

data_type *pointer_variable_name;

Let suppose, if we declare a pointer ptrX to store the memory address of an integer variable; then the pointer declaration will be int *ptrX;

B) To access the stored value of the memory (location) pointed by the pointer -

Consider the syntax

*pointer_variable_name;

Let suppose, if there is a pointer variable ptrX which is pointing to the address of an integer variable x; then to access the value of x, *ptrX will be used.

2. The & Operator (Address Of Operator) -

The "Address Of" Operator denoted by the ampersand character (&), & is a unary operator, which returns the address of a variable.

After the declaration of a pointer variable, we need to initialize the pointer with the valid memory address; to get the memory address of a variable Address Of" (&) Operator is used.

Code:-

#include <stdio.h>
int main()
{
	int x=10;	//integer variable
	int *ptrX;	//integer pointer declaration
	ptrX=&x;	//pointer initialization with the address of x
	
	printf("Value of x: %d\n",*ptrX);
	return 0;
}

Output:-

Value of x: 10

Conclusion:

Address operator is used to store the address of the variable in C. This is denoted by an ampersand (&). This is also used for scanning the user input.

C Language
Address Operators
Operator
Program
2 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 2 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance