In this article “Address Operator in C”, we explain two important operators — the Address Operator (&) and the Indirection Operator (*).
Address Operator in C
The Address Operator (&) and the Indirection Operator (*). Both are fundamental concepts in understanding pointers in the C programming language, as they deal with memory addresses and the values stored at those addresses.
Address Operator (&) in C
When we declare a variable in C, it has:
- A name (identifier)
- A data type (which defines the type of value stored)
- A size (depending on data type)
- And most importantly, a memory address, which tells where the variable is stored in the computer’s memory.
This memory address is automatically assigned by the system, not by the programmer.
To find out this memory address, we use the Address Operator (&).
Definition
The Address Operator (&) is a unary operator (acts on one operand) that returns the memory address of a variable.
It cannot be used with constants or expressions — only with variable names.
The & operator is also known as the Referencing Operator.
Syntax
&variable_name;
Example
#include <stdio.h>
void main()
{
int p = 15;
printf(“%d\n”, p); // prints the value of p
printf(“%p\n”, &p); // prints the memory address of p
}
Output:
15
0x7ffe5367e8a4
Note: The address will vary each time the program is executed.
Explanation:
- p holds the value 15.
- &p gives the memory address of p, which is displayed in hexadecimal format.
Asterisk (*) or Indirection Operator in C
The Asterisk (*), also called the Indirection Operator or Dereferencing Operator, is used to access the value stored at a memory address.
It is also a unary operator that acts on a single operand — the memory address of a variable.
Definition
The Indirection Operator (*) returns the value stored at the address specified by its operand.
It is mostly used with pointers to access or modify the value of a variable indirectly (through its address).
Syntax
*&variable_name;
Example
#include <stdio.h>
void main()
{
int x = 15;
int y = *&x; // dereferencing the address of x
printf(“y = %d”, y);
}
Output:
y = 15
Explanation:
Here,
- x is assigned the value 15.
- &x gives the address of x.
- *(&x) accesses the value stored at that address — i.e., 15.
Thus, y receives the same value as x.
Example: Address Operator (&) and Indirection Operator (*) Together
#include <stdio.h>
void main()
{
int x = 15;
printf(“%d\n”, x); // prints value of x
printf(“%p\n”, &x); // prints address of x
printf(“%d\n”, *&x); // prints value stored at address of x
}
Output:
15
0x7ffe5367e8a4
15
Explanation:
- The first printf() displays the value of x.
- The second printf() displays the memory address of x using the &
- The third printf() displays the value stored at the memory address using the *
Hence, the expression *&x simply returns the value of x, because & gives the address and * retrieves the value stored at that address.
Conclusion
The Address Operator (&) and Indirection Operator (*) are essential for understanding pointers in C programming.
- The & operator gives the address of a variable.
- The * operator retrieves the value stored at that address.
Together, they allow direct interaction with the computer’s memory — enabling efficient data manipulation, dynamic memory allocation, and pointer-based operations.
Some More:
POP- Introduction to Programming Using ‘C’
OOP – Object Oriented Programming
DBMS – Database Management System
RDBMS – Relational Database Management System
Join Now: Data Warehousing and Data Mining