References in C++

• Reference is an implicit pointer to a variable.
• Creating references: 

        int &r;
• Initializing:
        int i=10;
        int &r=i;
• To access value of a variable using reference
       cout<<r;
• But you cannot use ++, -- like pointers to move references to next location
• References are also const pointers and cannot be reassigned.
       r=&j; is not possible.
• The real need for a reference variable can be felt when we pass by reference variables.

No comments:

Post a Comment