Search code examples
cpointersnestedlimitpointer-to-pointer

How many consecutive nested pointer (pointer to pointer) can i have in one order? Is there a limit of doing references?


The follow program declares a pointer then again a new pointer to hold address of previous pointer variable.. How much can I use nested pointer variable to hold memory address is there any limit?

#include <stdio.h>
#include <conio.h>

void main()
{
    int x=2,y=5;

    int *ptr;
    int **sptr;
    int ***ssptr;

    ptr = &x; // address of x
    *ptr = 0; 
    sptr = &ptr;
    ssptr = & sptr;

printf(" address is ip = %u %u %u",ptr,sptr,ssptr);
    _getch();
}

Solution

  • There is no limit. A pointer is a chunk of memory (typically one word) whose contents are an address. A pointer to a pointer is also a word whose contents are an address, but it just so happens that the contents at that address is another address. There is nothing particularly special about a pointer to a pointer (to a pointer to a pointer... etc., ad nauseum).