1.

References and Pointers

Answer»
string variable1 = "Value1"; // a variable
string &variable2 = variable1; // reference to variable1

Reference is an alias for an already existing variable. Once it is initialized to a variable, it cannot be changed to refer to another variable. In the above example, variable2 is a reference to variable1.

A pointer is a variable that contains the memory address of another variable.

int var = 2, *p;
p = &var;// The variable p holds the address of the variable var int *const ptr;

ptr in the above code is a constant pointer.

const int* ptr;

The above code shows how to declare a pointer to a constant. 




Discussion

No Comment Found