Prerequisite :
Address Operator in C programming
How to Initialize Pointer in C Programming ?
pointer = &variable;
Example :
#include<stdio.h> int main() { int a = 10; int *ptr; ptr = &a; return(0); }
Explanation :
- Pointer should not be used before initialization.
- “ptr” is pointer variable used to store the address of the variable.
- Stores address of the variable ‘a’ .
- Now “ptr” will contain the address of the variable “a” .
Note :
Pointers are always initialized before using
Example : Initializing Integer Pointer
#include<stdio.h> int main() { int a = 10; int *ptr; ptr = &a; printf("\nValue of ptr : %u",ptr); return(0); }
Output :
Value of ptr : 4001

