Pointer to Pointer in C

Previous
Next

Pointer to pointer:

  • A pointer to pointer type variable holds address of another pointer variable.
  • It is also called double pointer.
  • Using these types of pointers, we can define complex pointers programming.
#include<stdio.h>
void main()
{
	int i = 100;
	int* ip;
	int** ipp;
	ip = &i;
	ipp = &ip;
	printf("%d,%d,%d", i, *ip, **ipp);
}

Array of Strings also represent as Pointer to pointer type variable only:

#include<stdio.h>
void main()
{
	char* s[] = {"abc","cde","efg"} ;
	int i ;
	for(i=0 ; i<3 ; i++)
	{
		printf("%c \n", *(*(s+i)+i));
	}
}

A complex example is here to analyze:

#include<stdio.h>
void main()
{
    char *s[ ] = {"black", "white", "pink", "violet"};
    char **ptr[ ] = {s+3, s+2, s+1, s};
    char ***p;
    p = ptr;     
    ++p;
    printf("%s\n", (*(*p+1)+1)+2);
}

Crack this:

#include<stdio.h>
void main()
{
    char *s[ ]={"black", "white", "pink", "violet"};
    char **ptr[ ] = {s+1, s, s+3, s+2};
    char ***p;
    p = ptr;
    p+1;
    printf("%c \n", *(*(*++p+1))+3);
}
Previous
Next

Add Comment

Courses Enquiry Form