Pointer to pointer in C | C Double pointer | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Friday, July 3, 2020

Pointer to pointer in C | C Double pointer | My CS Tutorial

Pointer to pointer in C | Double pointer in C | Declaration of double pointer | Example of double pointer | C - pointer to pointer | Double pointer in C programing | My CS Tutorial


Double pointer(pointer to pointer) in C | My CS Tutorial



We know that a pointer holds the address of another variable of same type. When a pointer holds the address of another pointer then such type of pointer is known as pointer-to-pointer or double pointer.
In this post, we will learn what is a pointer to pointer(double pointer), how to declare them and how to use them in C programming. To understand this concept, you should know the basics of pointers.


Pointer to Pointer (Double pointer) in C


A pointer to a pointer is a form of multiple indirection, or a chain of pointers.
Normally, a pointer contains the address of a variable. When we define a pointer
to a pointer, the first pointer contains the address of the second pointer, which
points to the location that contains the actual value as shown below.


Structure of double pointer in c | My CS Tutorial

Declaration of double pointer


A variable that is a pointer to a pointer must be declared as such. This is done
by placing an additional asterisk in front of its name. For example, the following declaration declares a pointer to a pointer of type int:-

int **ptr;

When a target value is indirectly pointed to by a pointer to a pointer, accessing that value requires that the asterisk operator be applied twice, as is shown below in the example:

#include<stdio.h>
#include<conio.h>
int main()
{
int num=10;    
int *p;
int **p2;      
clrscr();

p=&num ;    
p2=&p ;  

printf("Num variable address is = %x \n",&num);    

printf("p variable address is =%x \n",p);    

printf("*p variable value is = %d \n",*p);    

printf("p2 variable address is = %x \n",p2);    

printf("**p2 variable value is =%d \n",*p);    

return 0;
}


Output of this program is given below:-

Num variable address is = bee79840
p variable address is =bee79840
*p variable value is = 10
p2 variable address is = bee7983c
**p2 variable value is =10


Pointer to pointer in C | Double pointer in C | Declaration of double pointer | Example of double pointer | C - pointer to pointer | Double pointer in C programing | My CS Tutorial

_________________________________________


Please share this post and blog link with your friends.For more programs use this blog.

If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment