The pointer in C language is a variable which stores the address of another variable. This variable can be of type int, char, array, function, or any other pointer. 

Example:- int *a , char *a etc;

Syntax:

Data_type *variable_name;
Int *a;

Example:

#include<stdio.h>
#include<conio.h>
Void main()
{
     int a=5;
     int *pt;
           pt=&a;
     printf(“%d”,pt);
     getch();
}

Types of Pointers in C

1. Null Pointer in C
2. Void Pointer in C
3. Wild Pointer in C
4. Dangling Pointer in C
5. Near Pointer in C
6. Far Pointer in C
7. Huge Pointer in C
8. Pointer to pointer

Null Pointer in C

Example:

#include<stdio.h>
#include<conio.h>
Void main()
{
    int *pt=NULL // pt is a null pointer in c
    printf(“%d”,pt);
    getch();
}

Void Pointer in C

Example:

#include<stdio.h>
#include<conio.h>
Void main()
{
    void *pt; // pt is a void pointer in c
     int a=5;
     pt=&a;
    printf(“%d”,pt);
    printf(“%d”,*(int *)pt);
    getch();
}

Wild Pointer in C

Example:

#include<stdio.h>
#include<conio.h>
Void main()
{
    int *pt;// pt is a wild pointer in c
    
    getch();
}

Dangling Pointer in C

Example:

#include<stdio.h>
#include<conio.h>
Void main()
{
    int *pt;
    {
        int a=10;
        pt=&a;
       printf(“%d\n”,a);
       printf(“%d\n”,pt);
       printf(“%d\n”,*pt);
    }
       Printf(“after Block\n”);
       printf(“%d\n”,a);
       printf(“%d\n”,pt);
       printf(“%d\n”,*pt);
       getch();
}

Near Pointer in C

Example:

#include<stdio.h>
#include<conio.h>
Void main()
{
    int n=5;
    int near* pt=&n;
    int s=sizeof(pt);
    printf(“%d”,s); 
    getch();
}

Far Pointer in C

Example:

#include<stdio.h>
#include<conio.h>
Void main()
{
    int n=5;
    int far* pt=&n;
    int s=sizeof(n);
    printf(“%d”,s); 
    getch();
}

Huge Pointer in C

Example:

#include <stdio.h>

int main() 
{
   int* p, n;
   
   n = 10;
   printf("Address of n: %p\n", &n);//prints the address of n
   printf("Value of n: %d\n\n", n);  // value of n
   
   p = &n;
   printf("Address of pointer p: %p\n", p);//memory location p is     pointing
   printf("Content of pointer p: %d\n\n", *p); // value at that location
   
}

Pointer to pointer

Example:

#include <stdio.h>
#include<conio.h>
void main() 
{
       int a = 10;  
       int *p;  
       int **pp;   
       p = &a;  
       pp = &p;   
       printf("address of a: %x\n",p);   
       printf("address of p: %x\n",pp);  
       printf("value stored at p: %d\n",*p);  
       printf("value stored at pp: %d\n",**pp);   
       getch();

}

Benefits of Pointers

One of the major advantages of using pointers is dynamic memory allocation which accelerates the program execution when we have any task of updating the variable in different time frames as the variable is directly accessible.

Watch the Video Lecture


            Previous                                                                                                                       Next