C pointer basic concept
Understanding pointers in c ?
In the previous chapter we have learnt about Basic Concept of Pointer. In this chapter we are looking more into pointer.
We know that -
- Pointer is a variable which stores the address of another variable
- Since Pointer is also a kind of variable , thus pointer itself will be stored at different memory location.
2 Types of Variables :
- Simple Variable that stores a value such as integer,float,character
- Complex Variable that stores address of simple variable i.e pointer variables
Simple Pointer Example #1 :
#include<stdio.h> int main() { int a = 3; int *ptr; ptr = &a; return(0); }
Explanation of Example :
Point | Variable 'a' | Variable 'ptr' |
---|---|---|
Name of Variable | a | ptr |
Type of Value that it holds | Integer | Address of Integer 'a' |
Value Stored | 3 | 2001 |
Address of Variable | 2001 (Assumption) | 4001 (Assumption) |
Simple Pointer Example #2 :
#include<stdio.h> int main() { int a = 3; int *ptr,**pptr; ptr = &a; pptr = &ptr; return(0); }
Explanation of Example
With reference to above program -
We have following associated points -
Point | Variable 'a' | Variable 'ptr' | Variable 'pptr' |
---|---|---|---|
Name of Variable | a | ptr | pptr |
Type of Value that it holds | Integer | Address of 'a' | Address of 'ptr' |
Value Stored | 3 | 2001 | 4001 |
Address of Variable | 2001 | 4001 | 6001 |
Conclusion :
In this tutorial we have seen simple pointer examples and how it is represented or stored in memory.
In the next chapter we will look into Address Operators in C programming.