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.


0 comments:

Post a Comment

Data Structures with C++



NET/SET/CS PG



Operating Systems



Computer Networks



JAVA



Design and Analysis of Algorithms



Programming in C++

Top