Pointer is a variable that is used to contain the address of another variable. We can easily create a pointer in C language.
Example: int *ptr
|& (ampersand sign)||Address of an operator is used to contain the address of a variable.|
|* (asterisk sign)||Indirection operator is used to accesses the value at the address..|
Advantage of pointer
In C language, there are various advantages of pointer that are given below:
- It is used to reduce the code and performance.
- It accesses the direct address of the variable.
- It is used to return multiple values from the function.
- It helps us to access any memory location from the pointer.
How can we declare pointer
We can declare pointer by using * (astric symbol).
Let us consider an example:
int main ()
int *ptr; // pointer variable
printf("Address of num variable: %x\n", &n);
printf("Address stored in ptr variable: %x\n", ptr ); // address stored in
printf("Value of *ptr variable: %d\n", *ptr ); //access the value using the
Address of num variable: f64b7adc
Address stored in ptr variable: f64b7bd0
Value of *ptr variable: 1
A pointer does not assign any value that is known as a NULL pointer. We can create a null pointer at the time of declaration.