- What is a variable in C++?
- What is Definition of a variable?
- What is Instantiation of a variable?
- What is the difference between an l-value and an r-value?
- What is an uninitialized variable and what kind of behavior can you expect from such a variable?
- What is undefined behavior?
In C++, a variable is an object that has a name. An object is a piece of memory that is allocated to store values.
A variable can be defined in C++ by using a declaration statement. The data type is stated, followed by the variable name.
data_type variable_name;
An instantiation is a piece of memory set aside by the RAM. An instantiation is executed by the CPU after defining a variable.
An l-value has a persistent address in memory. An r-value does not have a persistent address in memory. For example, the statement
int x;
vs
int 5;
The first creates a new persistent address in the memory of type integer named x. The latter does not create a change in persistent memory because the 5 is not an l-value.
An uninitialized is a variable that has not ben assigned a memory by the compiler and the default value is whatever garbage happens to be there in that memory location.
It is the result of executing code whose behavior is not defined by the language. One example is using a uninitialized variable.