-
What is a variable in C++?
A named object is called a variable. A variable is a named object which serves as region of storage (usually memory) that has a value and other associated properties. -
What is Definition of a variable?
In order to create a variable, we use a special kind of declaration statement called a definition wherein the object is assigned a name and type. -
What is Instantiation of a variable?
When the program is run (called runtime), the variable will be instantiated. Instantiation is a fancy word that means the object will be created and assigned a memory address. Variables must be instantiated before they can be used to store values -
What is the difference between an l-value and an r-value?
An l-value is a value which has an address. Thus all variables are l-values since variables have addresses. Since the name l-value stands for left-value, so these are always on the left side in an assignment statement (a statement in which we assign the value from the right side to the left side). Therefore whenever a variable is assigned some value, it is always written on the left side of the assignment operator (=).
In C++, the value on the right side of = is assigned to the left side. E.g.- x = 8 will make x equal to 8 but 8 = x will give you error because you canât assign any value to 8, which is not a variable.
An r-value is a value which is assigned to an l-value. For example, in the statement x = 8; , x is a l-value since it is a variable to which some value is being assigned and 8 is an r-value since it is being assigned to x. Note that when we write 5 = 8; , there will be a compilation error because 5 is not an l-value (since it is not a variable having any memory space).
-
What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
An uninitialized variable is the one to which we have not assigned any value. Unlike some programming languages where a variable which has not been assigned any value takes a value zero, an uninitialized variable in C++ by default takes some garbage value. -
What is undefined behaviour?
- undefined behavior - there are no restrictions on the behavior of the program. Examples of undefined behavior are memory accesses outside of array bounds, signed integer overflow, null pointer dereference, [more than one] modifications of the same scalar in an expression without any intermediate sequence point (until C++11) that are unsequenced (since C++11), access to an object through [a pointer of a different type etc. Compilers are not required to diagnose undefined behavior (although many simple situations are diagnosed), and the compiled program is not required to do anything meaningful.
** hackers use this in buffer overflow attacks to take over computers ; }