C - Pointers to Pointers

Example 1: Program to illustrate the use of Pointers to Pointers

void main()
{
    int a=10, *p;
    p=&a;

    printf("\nValue of A = %d", a); //10
    printf("\nAddress of A = %d",&a);
    printf("\nValue of p = %d",p);
    printf("\nAddress of P = %d",&p);
    printf("\nPointer of p = %d",*p); //10
    int **q;
    q=&p;
    
    printf("\nValue of Q = %d",q);
    printf("\nAddress of Q = %d",&q);
    printf("\nPointer of Q = %d",**q); //10
    getch();
}

Example 2:

void main()
{
    int **p = (int **) malloc(3*sizeof(int*));
    int i, j;
    clrscr();
    for(i=0;i<=2;i++)
    {
        p[i]=(int*) malloc(3*sizeof(int));
        for(j=0;j<=2;j++)
        {
	        scanf("%d",&p[i][j]);
        }
    }

    for(i=0;i<=2;i++)
    {
        for(j=0;j<=2;j++)
	        printf("%d\t",p[i][j]);
        printf("\n");
    } 

    getch();
}