### Storing the result of reference (&) operator in reference data typed variables

• Assigning a reference value to a reference variable

• Recall that:

• The reference operator & "computes" (returns) the address of a variable:

 ``` int a; &a returns: the address of the variable a ```

Note:

 Because the variable a is of the type int, the address &a is an address of an int typed variable !!!

• We have just learned how to define a variable where you can store an address of an int typed variable:

 ``` int *p ; ```

• So now it should obvious that you can assign a reference value to a reference typed variables:

 ``` int a; // an int typed variable // So: a can store an integer value int *p; // p can hold an address of an int typed variable // So: p can store an address of an integer variable p = &a; // Store the address of the int type variable a in p ```

• The following diagram depicts what happens inside the computer:

• First, the variable definitions will allocated (reserve) space in the memory:

The address of the variable a is 5000,     i.e.: &a = 5000 !!!

Notice that:

 int *p defines a variable named p !!! The data type of p is reference to an int

• The assignment statement p = &a; will store the address of the variable a (= 5000 !!!) into the (reference) variable p:

• Result: the variable p points to the variable a: