Memory allocation for links

Read the many differences between pointersand references.

Here is a brief description of what I learned.

1 . Memory is allocated when a pointer is specified. However, the reference is an alias of the name and therefore no memory is allocated for it ( Is it correct?).

2 . The link must be initialized during the definition, because the link is implemented using a constant pointer and, therefore, cannot be pointed to another object. However, the pointer does not have to be initialized during the definition and, therefore, can also be changed to indicate any other object.

3 . The link automatically receives the link. When you write cout << p; It is automatically canceled by the link by the compiler and processed as cout << *p; the compiler.

Here p is a link.

  • Link to link is not possible. In any case, you declare a link to the link, its actual link to the same variable. eg.

    int i;    
    int &r1=i;    
    int &r2=r1; <-------------------2
    

The compiler interprets operator 2 as:
         int & r2 = (* r1)
and (* r1) - nothing more than the variable i itself.

However, a pointer to a pointer is possible.

5 . An array of pointers is possible, and an array of references is impossible (why?).

6 . Pointer address is possible. Link address is not possible. It gives the address of the variable.

7. , . . :

A a = b + c;

a, b, c - A. "+" :

const A& operator+(const A& o)
{
     return A(i+o.i);
}

: http://ideone.com/Q0pE1

.
, .
   A a = & b + & c.
, , , .

, - , ?

?

+5
1

. , , , , .

""? , , new malloc - , no:

int val = 5;
int *pVal = &val; //No dynamic memory allocation.

, , int . "".

, , , .

, , . . , , . , , .

, .

.

. . - . .

, (?).

, . , . , . .

. . .

- . ; .

, .

operator+ :

A operator+(const A *lhs, const A *rhs) {...}

, .

, :

const A& operator+(const A& o)
{
     return A(i+o.i);
}

. const& . .

+7

All Articles