Posts

Showing posts from November, 2020

Can You Re-Assign Reference Variables in C++?🤔

Image
To start with let us define what is meant by Reference Variable. Reference variable is a type of variable which is regarded as an alias name to an existing variable. Declaring a reference variable I have used a code snippet from C++ programming language Here as you can see that I have declared a variable of type  integer  and named it as val, As soon as the compiler compiles the statement  memory is allocated for the variable val in the stack and initialized with the value 10. With the next statement we are creating a reference variable named ref which is referring the variable val. This also means that there is no separate  memory allocated for the variable ref whereas it is just  another  name for the memory location identified by val. Can we Reassign it? The next question which comes to mind is whether it is possible to reassign the reference variable to  refer some other variable at run time for example: In the above example I have created two inte...