Address of operator or Reference operator(&)


We can initialize the pointer variable by assigning the address of some other variable. The address of the variable can be obtained by preceding the name of the variable with address operator(&). This operator returns the address of variable. For example,

                                                            int i=5;
                                                            int *ptr=&i;

In the second statement, pointer variable ptr is initialized with address of variable i as shown.


We can also define the variable i and initialize the pointer variable ptr with the address of
variable i in a single statement provided the variable i is defined before ptr.
 
                                                int i=5,*ptr=&i;



Previous                                                                                    Next


Powered by Blogger.