double pointer in c

Double Pointer in C

In C, a double pointer is a pointer that points to another pointer. It is also known as a pointer to a pointer.

Here is an example of how a double pointer can be declared and used in C:

#include <stdio.h>

int main() {
    int num = 10;
    int *ptr = &num; // pointer to an integer
    int doublePtr = &ptr; // double pointer

    printf("Value of num: %d\n", num);
    printf("Value of ptr: %d\n", ptr);
    printf("Value of doublePtr: %d\n", doublePtr);

    return 0;
}

In the above example, we have a variable num of type int. We declare a pointer ptr that points to the memory address of num. Then, we declare a double pointer doublePtr that points to the memory address of ptr.

To access the value of num using the double pointer, we use the operator. The expression doublePtr gives us the value of num.

Output:

Value of num: 10
Value of *ptr: 10
Value of doublePtr: 10

This is a basic example to demonstrate the concept of a double pointer in C. Double pointers are commonly used in scenarios where we need to modify the value of a pointer itself or pass a pointer to a function by reference.