Write a C Program to show an example of pointer to pointer

By | 19.03.2017

C Program to understand pointer to pointer


Write a C Program to understand pointer to pointer. Here’s a Simple Program which shows an example to understand pointer to pointer in C Programming Language.


Pointer to Pointer :


  • 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
  • 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.
  • The declaration of a pointer-to-pointer looks like :
  • int **ipp;
  • where the two asterisks indicate that two levels of pointers are involved.

Below is the source code for C Program to show an example of pointer to pointer which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/* Program to understand pointer to pointer*/

#include<stdio.h>

int main( )
{
        int a = 5;
        int *pa;
        int **ppa;
        pa = &a;
        ppa = &pa;
        printf("Address of a = %p\n", &a);
        printf("Value of pa = Address of a = %p\n", pa);
        printf("Value of *pa = Value of a = %d\n", *pa);
        printf("Address of pa = %p\n", &pa);
        printf("Value of ppa = Address of pa = %p\n", ppa);
        printf("Value of *ppa = Value of  pa = %p\n", *ppa);
        printf("Value of **ppa = Value of a = %d\n", **ppa);
        printf("Address of ppa = %p\n", &ppa);

    return 0;

}

OUTPUT : :


Address of a = 000000000062FE4C
Value of pa = Address of a = 000000000062FE4C
Value of *pa = Value of a = 5
Address of pa = 000000000062FE40
Value of ppa = Address of pa = 000000000062FE40
Value of *ppa = Value of  pa = 000000000062FE4C
Value of **ppa = Value of a = 5
Address of ppa = 000000000062FE38

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post.

5 1 vote
Article Rating
Category: C Programming Pointer Programs Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments