Q:

C program to perform double pointer or Pointer to Pointer

0

Write a C program to perform double pointer or Pointer to Pointer. Here’s simple program to perform double pointer or Pointer to Pointer in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

What are Pointers?


A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.

 
 

The general form of a pointer variable declaration is −

  • type *var-name;

Here, type is the pointer’s base type; it must be a valid C data type and var-name is the name of the pointer variable.

The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer.

 

The unary or monadic operator & gives the “address of a variable’”.

The indirection or dereference operator * gives the “contents of an object pointed to by a pointer”.


Below is the source code for C program to perform double pointer or Pointer to Pointer which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :

/*  C program to perform double pointer or Pointer to Pointer  */

#include <stdio.h>

int main()
{
    int a;          //integer variable
    int *p1;            //pointer to an integer
    int **p2;           //pointer to an integer pointer

    p1=&a;          //assign address of a
    p2=&p1;         //assign address of p1

    a=100;          //assign 100 to a

    //access the value of a using p1 and p2
    printf("Value of a (using p1): %d",*p1);
    printf("\n\nValue of a (using p2): %d",**p2);

    //change the value of a using p1
    *p1=200;
    printf("\n\nAfter Changing, Value of a (using p1): %d",*p1);
    //change the value of a using p2
    **p2=200;
    printf("\n\nAfter Changing, Value of a (using p2): %d",**p2);

    return 0;
}

Output : :


/*  C program to perform double pointer or Pointer to Pointer  */

Value of a (using p1): 100

Value of a (using p2): 100

After Changing, Value of a (using p1): 200

After Changing, Value of a (using p2): 200

Process returned 0

Above is the source code for C program to perform double pointer or Pointer to Pointer which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Pointer Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C program to perform Array of pointers... >>
<< Write a C program to print size of different data ...