Understanding pointers in c ?
- Pointer is a variable which stores the address of another variable
- Since it is a variable , the pointer itself will be stored at different memory location.
In C Programming we have 2 types of variables -
- Simple Variable that stores a value
- Complex Variable that stores address of simple variable
Simple Example 1 :
#include<stdio.h> int main() { int a = 3; int *ptr; ptr = &a; return(0); }
Explanation of Example : Consider Variable ‘a’ –
- Name of Variable – a
- Type of Value that it holds – Integer
- Value Stored in a – 3
- Address of Variable – 2001 (Assumption)
Explanation of Example : Consider Variable ptr –
- Name of Variable – ptr
- Type of Value that it holds – Address of any Integer
- Value Stored in a – 2001
- Address of Variable – 4001 (Assumption)
Simple Example 2 :
#include<stdio.h> int main() { int a = 3; int *ptr,**pptr; ptr = &a; pptr = &ptr; return(0); }
Explanation of Example : Consider Variable ‘a’ –
- Name of Variable – a
- Type of Value that it holds – Integer
- Value Stored in a – 3
- Address of Variable – 2001 (Assumption)
Consider Variable ptr –
- Name of Variable – ptr
- Type of Value that it holds – Address of any Integer
- Value Stored in a – 2001
- Address of Variable – 4001 (Assumption)
Consider Variable pptr –
- Name of Variable – pptr
- Type of Value that it holds – Address of any Pointer Vaiable
- Value Stored in a – 4001
- Address of Variable – 6001 (Assumption)


