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 -

  1. Pointer is a variable which stores the address of another variable
  2. Since Pointer is also a kind of variable , thus pointer itself will be stored at different memory location.

2 Types of Variables :

  1. Simple Variable that stores a value such as integer,float,character
  2. 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 :

PointVariable 'a'Variable 'ptr'
Name of Variableaptr
Type of Value that it holdsIntegerAddress of Integer 'a'
Value Stored32001
Address of Variable2001 (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 -

PointVariable 'a'Variable 'ptr'Variable 'pptr'
Name of Variableaptrpptr
Type of Value that it holdsIntegerAddress of 'a'Address of 'ptr'
Value Stored320014001
Address of Variable200140016001

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.