Pointer is a variable that is used to contain the address of another variable. We can easily create pointer in C language.
Example: int *ptr
|& (ampersand sign)||Address of 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 variable.
- It is used to return multiple values from function.
- It helps us to access any memory location from 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 pointer variable
printf("Value of *ptr variable: %d\n", *ptr ); //access the value using the pointer
A pointer does not assign any value that is known as NULL pointer. We can create null pointer at the time of declaration.
Example: int *ptr=NULL: