Variables in C++ - Reading Assignment

  1. A variable in C++ is an area of storage which is given a name.
  2. A variable is a named object which stores data.
  3. Instantiation of a variable refers to its creation and its assignment to a memory location during runtime.
  4. An l-value has an identifiable memory address. And r-value does not.
  5. An uninitialized variable does not have an assigned value and will produce unpredictable results.
  6. Undefined behavior is the result of executing code whose behavior is not defined. This can cause bugs in the code but does not necessarily indicate an error.
1 Like
  1. An object with a name to store values.
  2. Definition is a special kind of declaration for a variable, for example int x; // - defines a variable named x, of type int.
  3. Instantiation makes space in “RAM” for variables.
  4. I-values retain in memory while r-values don’t so they don’t have to be associated with any specific memory address
  5. It lacks any assigned value while staying in the memory so it can cause crashes or unexpected errors.
  6. When the program doesn’t react accordingly or show expected results. This can happen either at the very beginning of its operation or later.
1 Like

A variable is a named object, stored in the computer’s memory.

Variable is an object with a specified type that will be stored in memory. We can assign values to this object, and we will be able to access these values by referencing their identifier.

The assignment of a memory slot to a variable. Variables must be instantiated before we are able to add values to them.

An l-value has a persistent address in memory.
r-value is a temporary value.

Uninitialised variables are variable names that have an allocated address in memory, but we haven’t yet assigned a value to.
When we use uninitialised variables in any way, we will get a value that was already held in the memory address, where the compiler placed the uninitialised variable.

When we accidentally use this value, we will get unexpected, inconsistent results.

1 Like
  1. A Variable is an object that has a name. This object is a piece of memory that is allocated to store values.
  2. It’s a memory that has a name and is currently defined.
  3. It happens when the peace of memory is set a space in the RAM.
  4. An I-value is a variable that has a persistent address in memory and r-value is not associated with a persistent memory address.
  5. It’s a variable that has no memory location.
  6. Unpredictable behavior results.
1 Like
  1. Any named object is called a variable.
  2. A named region of storage that can store a data value.
    3 Creating of an object and assigning it a memory address.
  3. There is no answer in that article
    5 There is no answer in that article
    6 There is no answer in that article

Please tell me where to look!

4. What is the difference between an l-value and an r-value?
5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
6. What is undefined behaviour?

Hello sir, there is an answer for those questions, take a look on this website and books so you can find a great answer please!

Also you can try to look at google, to see if you find even more info about it!

Hope you find this useful! :slight_smile:

If you have any doubt, please let us know so we can help you!

Carlos Z.

1 Like
  1. A variable is a named object and an object is a storage region in a computer’s memory.
  2. At bottom all data in a computer’s memory is stored in the form of sequences of zeroes and ones (on- or off-states of transistors). So in order for a program to know how to interpret the zeroes and ones that are stored in the region of memory to which a given variable refers, the program must be given a mode of interpretation, and it is precisely this mode of interpretation that the definition of a variable specifies.
  3. An instantiation of a variable is an assignment of a concrete value to a variable.
  4. In an equation that assigns a specific value to a variable, the variable is placed, by convention, on the left-hand side of the equal sign and the specific value is placed on the right-hand side. Thus the former is referred to as the l-value (or left-value) and the latter as the r-value (or right-value).
  5. An uninitialized variable is a variable that has been defined but that has not been assigned a specific value.
  6. Undefined behavior occurs when a program instruction references, as it were, a value or a memory location that is out of bounds. All value ranges in a computer are necessarily finite, and a reference to a value outside such a finite range causes an effect that is undefined in the sense of being strange, unexpected or erratic.
1 Like
  1. A variable is a named object.
  2. The definition of a variable is that it is a memory location that holds a value.
  3. Assigning and reserving memory RAM for a specific variable.
    4.I-value: Have a place in memory. R-values: Not in memory.
    5.An uninitialized variable is in the memory, but it does not have a value to it. This can lead to unexpected behaviour.
  4. This runs code that is not well defined by language.
1 Like

1. What is a variable in C++?
A named object, which holds values.

2. What is the Definition of a variable?
A declaration statement, giving a name to the object .

3. What is Instantiation of a variable?
Creation of the object, which gets a memory address assigned.

4. What is the difference between an l-value and an r-value?
l-values are values that have their place in memory, r-values are values (or expressions) that are discarded at the end of a statement and therefore need not to be associated with a memory address.

5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
A declared variable whose value in the memory address has not yet been initialized.

6. What is undefined behavior?
The result of executing code whose behavior is not well defined by the language.

1 Like
  • What is a variable in C++?
  • What is the 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?
  1. A variable in C++ is a region of memory that is named and can be referred to when requested.
  2. The definition of a variable is basically a descriptor of the data stored - a variable is assigned parameters such as a name and a data type. This means the computer can refer to that variable by its name and the the compiler knows what type of data is stored (e.g. string, int, float, etc.)
  3. Instantiation of a variable occurs at run time and it means that an object (such as a variable) is created and is given a memory address. The program can then refer to that instance throughout the program.
  4. An L-value is referred to as the left hand side of an assignment, it is identified and therefore we can reference it - for example a named variable. An R-value is an object that is assigned to an L-value (this is generally a temporary value) and can be stored to memory, changed or removed. An example of an R-value would be an integer or string, etc.
  5. An unitialised variable is a variable that has not yet been given a value (by initialisation or assignment) and therefore has an unknown value assigned to it which could result in undefined behaviour.
  6. Undefined behaviour is the result of executing poorly defined code (for example uninitialised variables). This could cause the program to return different results each time it is run, return consistently incorrect results, return inconsistent results (sometimes correct sometimes not) or crash the program, etc.
1 Like
  1. It’s a named region of memory
  2. type and identifier -> i.e.: int a;
  3. A variable is defined and assigned a value -> int a = 3;
    4 An l-value has a persistent address in the memory whereas r-value not
  4. An uninitialised variable is a variable without a assigned value.
  5. Executing code that is not well defined.
1 Like

Excellent answer sir! really well documented! keep it like that please! :muscle:

Carlos Z.

2 Likes
  1. What is a variable in C++?
    Answer: A variable is a named object which is a named region of memory. Variables are accessed by their identifier.

  2. What is the Definition of a variable?
    Answer: Definition is a special kind of declaration statement used to create a variable.

  3. What is Instantiation of a variable?
    Answer: Instantiasion is a fancy way of saying the variable will be created and assigned a memory location.

  4. What is the difference between an l-value and an r-value?
    Answer: An I-value has an identifiable location in memory. An r-value does not have an identifiable location in memory.

  5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    Answer: Since it is uninitialized the variable will have some value but no defined value. It is often the source of a bug in programming since its behavior is unpredictable or at best simply reflects the most recently defined variable.

  6. What is undefined behavior?
    Answer: It is exactly as it sounds. The code executes but the behavior is unpredictable due to weaknesses in the code such as uninitialized variables or undefined sets, types etc.

2 Likes

What is a variable in C++?

An object with a name.

What is the Definition of a variable?

A region of memory.

What is Instantiation of a variable?

Assigning a memory address for a variable in the RAM, which will be executed by the CPU.

What is the difference between an l-value and an r-value?

l-value has the same persistent address and the r-value is not associated with a persistent memory address.

What is an uninitialized variable and what kind of behavior can you expect from such a variable?

An uninitialized variable has no memory location. Using such variables can lead to unpredictable results.

What is undefined behavior?

Undefined behavior basically means unpredictable results.

1 Like

A named object.

A declaration statement of the variable

Instantiation is when the object is created and stored in a memory address.

I-values have a memory address, whereas r-values do not.

It is a declared object, but you don’t know what its behavior will be.

The results of this code will not have a defined outcome; may be successful, may fail.

2 Likes

Thanks mate, appreciate the feedback and encouragement

1 Like
  1. A variable is an object with a name and then object is a piece of memory which is use to store values.
  2. A declaration statement which we use to create a variable.
  3. It means the object variable will be created and assigned a memory address.
  4. I-value is a value that has a persistent address in memory whereas an r-value refers to values that are not associated with a persistent memory address. r-values are generally temporary in nature and are discarded at the end of the statement in which they occur.
  5. An uninitialized variable is a variable that has not been given a known value. If it is used, it will produce whatever value is present at its memory location but will never be constant due to the change in memory.
  6. The result of executing code whose behavior is not defined.
1 Like
  1. What is a variable in C++?
    A variable is a named object.

  2. What is the Definition of a variable?
    It’s the statement used to create a variable.

  3. What is Instantiation of a variable?
    It’s when memory is reserved for a variable in RAM. The variable is also known as an instance.

  4. What is the difference between an l-value and an r-value?
    The l-value (left) contains the persistent address in memory while the r-value (right) is the temporary value that’s stored at that location.

  5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    Uninstantiated variables are not given known values and if used it will return whatever value was there before by the previous program causing unpredictable behavior.

  6. What is undefined behavior?
    Code that was not well defined and unable to be interpreted.

1 Like

What is a variable in C++?

A variable in C++ is an object and the name of the object is called the identifier.

What is the Definition of a variable?

The definition of a variable is an object which points to an area in memory where a piece of data and its properties are stored.

What is Instantiation of a variable?

Instantiation of a variable is the assignment of a memory location to a variable so it can be assigned a value at a later time.

What is the difference between an l-value and an r-value?

  1. l-values can appear on the left hand side of an assignment expression denoting an object.
  2. r-values typically sit on the right hand side of an assignment expression and are temporary values not associated with an object.

What is an uninitialized variable and what kind of behavior can you expect from such a variable?

An uninitialized variable is a variable which has not been assigned a value yet. The type of behavior to expect is that it would return a 0 or null value.

What is undefined behavior?

Undefined behavior is the result of executing a program whose behavior is unpredictable in the language the computer adheres to.

1 Like
  1. An object that is named is called a variable.

  2. an element, feature, or factor that is liable to vary or change.

  3. it will be created and given a memory address.

  4. lvalue has accessible address and rvalue doesn’t persist beyond the single expression.

  5. A variable that has not been given a value. Undefined behavior.

  6. is the result of executing a program whose behavior is prescribed to be unpredictable,

1 Like