Full Stack Developer
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.
Address operators are commonly used for 2 purposes:
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:-
"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
Consider the syntax
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;
Consider the syntax
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.
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.
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);
Value of x: 10
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.
Subscribe to get latest updates