***Welcome to ashrafedu.blogspot.com * * * This website is maintained by ASHRAF***

Posts

    Thursday, November 26, 2020

    Pointers to Pointers

    C allows the use of pointers that point to pointers, and these, in turn, point to data. For pointers to

    do that, we only need to add an asterisk (*) for each level of reference. 

    Consider the following declaration.

    int a=5;

    int *p;    //pointer to an integer

    int **q;  // pointer to a pointer to an integer

    p=&a;

    q=&p;

    To refer to a using pointer p, dereference it once, that is, *p.

    To refer to a using q, dereference it twice because there are two levels of indirection involved.

    If q is dereferenced once, actually p is referenced which is a pointer to an integer.





    No comments:

    Post a Comment

    Top