Variables in C++ - Reading Assignment


#102

What is a variable in C++?

A variable in C++ is an object that has a name.

What is Definition of a variable?

A special kind of declaration statement that is used to create a variable

What is Instantiation of a variable?

A piece of memory from RAM that is set aside when the CPU executes a statement that creates a variable. Whenever the program sees that variable in an expression or statement, it knows to look in the memory location set aside for the variable.

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

An l-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.

In addition, l-values are the only values that can be on the left side of an assignment statement.

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

A variable that has not been given a known value (through initialization or assignment) is called an uninitialized variable . In C++ when a variable is assigned a memory location by the compiler the default value of the variable is whatever value already happens to be in the memory location and using the variable will result in undefined behavior (i.e. you cannot predict what will happen when you use the uninitialized variable.

What is undefined behaviour?

Undefined behavior is the result of executing code whose behavior is not well defined by the language. For example, C++ doesn’t have any rules determining what happens if you use the value of a variable that has not been given a known value. Consequently, if you actually do this, undefined behavior will result.

#1 3

#2 3

#3 6

#4 3

#5 undefined behavior – can’t determine in advance what the value will be

#6 What is undefined behaviour?

Undefined behavior is the result of executing code whose behavior is not well defined by the language. For example, C++ doesn’t have any rules determining what happens if you use the value of a variable that has not been given a known value. Consequently, if you actually do this, undefined behavior will result (e.g. in the case of an uninitialized variable you won’t know in advance what the output value of the variable will be).


#103

What is a variable in C++?

C++ is an object that has a name.

What is Definition of a variable?

A declaration statement used to create a variable is called a definition

What is Instantiation of a variable?

This is a declaration statement called a definition that is executed by CPU in which a piece of memory from RAM will be set aside in a memory location.

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

l-value can only be a value that has a persistent address and only be on the left hand side of an assignment statement. r-value are values that are not associated with a persistent statement and only be on the right hand side of an assignment statement.

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

An unitialized 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.

What is undefined behavior?

This is the result of executing code whose behavior is not defined.


#104

Response to Quiz 1-6 of the reading assignment. I think I am going to like C++, so far the logic to me really makes sense.

  1. 3
  2. 3
  3. 6
  4. 3
  5. 4354256/ which is indeterminate. Z is an unitialized variable.
    6)Undefined behavior occurs when the program inplements code whose behavior is not well defined by the language. When code with undefined behavior is impemented, the program may exhibit unexpected results.

#105

1- A variable in C++ is an object with a name
2- A definition of a variable is the type of data the variable can contain. As an example int x = 0 defines an integer variable, named X, with the value 0
3- Instantiation of a variable is when it is assigned space in RAM
4- An l-value goes to the left of a statement, and it is instantiated, r-values go to the right of a statement and have no persistent memory address.
5- An uninitialized variable is one that is instantiated but hasn’t been given a specific value. As such, it can contain any value currently assigned to its memory address.
6- Undefined behavior is when the program has code in it whose result is unpredictable. An uninitialized variable for instance, is one such case of undefined behavior.


#106
  1. What is a variable in C++?
    An object with a name.

  2. What is Definition of a variable?
    it is a declarative statement that gives meaning to the variable.

  3. What is Instantiation of a variable?
    allocating a memory location in RAM to store the variable value.

  4. What is the difference between an l-value and an r-value?
    an l-value can be stored in a memory address while the r-value cannot.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    an unitialized variable has not been assigned a value, so it use whatever garbage value was in it’s assigned memory address.

  6. What is undefined behaviour?
    It is program behavior that is unintended, and not guaranteed to provide consistent or correct values.


#107
  1. It is an object that goes into memory. Something like int x = 5. The object that goes into memory is x, which has been assigned the value of five.

  2. The definition of the variable is a declarative statement, something like int x.

  3. Instantiation is when a piece of memory is set aside for the variable.

  4. An l-value is something that’s in a set spot in memory. In the case of int x = 5; x is an l-value in memory. Something like 5 in the case above is an r-value. It is more temporary and can be erased from one line to the next.

  5. An uninitialized variable is one that has not been assigned a value. In the case of int x; calling that variable without assigning anything else to it can cause problems. A random section of memory will be assigned to the variable which could result in anything happening as far as what it returns.

  6. Undefined behavior is something that happens when code is executing that is not well defined in the language. In other words, the code may only work partially as intended, may produce other outcomes that were not anticipated, may break down halfway through running, etc. The instance of using an uninitialized variable would apply to undefined behavior.


#108
  1. What is a variable in C++?
    A named object

  2. What is Definition of a variable?
    a memory location for holding a value for an object

  3. What is Instantiation of a variable?
    A piece of memory that is set aside

  4. What is the difference between an l-value and an r-value?
    l- value is a value that has a persistent address
    r value not associated with a perisistent memory adress

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    A variable that has not been given a known value (through initialization or assignment) is called an uninitialized variable.

  6. What is undefined behavior?
    it behaviors random because it hasnt been defined so no variable can be, the computer just throw some random crap number to it


#109

1. What is a variable in C++?

The technical definition is that a variable is an object with a name. In simpler terms it is a location in memory to store data.

2. What is Definition of a variable?

A variable definition would be for example: int x; There are different variable types in c++ and an integer is just 1 of them, here we define this variable as an integer.

3. What is Instantiation of a variable?

Instantiation is simple the point where a specific place in memory is allocated to the variable name.

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

An l-value has a place in memory where as an r-value is only temporary and does not last after the statement is complete.

5. What is an uninitialised variable and what kind of behaviour can you expect from such a variable?

If a variable is defined abut not assigned eg. int x; cout << x; would print a random piece of data which just happens to be previously stored in the computers memory before this memory space was assigned to the variable. This data is unrelated to the program and its operations. If the variable is not assigned and used it can cause undefined behaviour.

6. What is undefined behaviour?

Undefined behaviours is unexpected program behaviour that can result for reasons such as that described in the question above or more generally where the executed code is not well defined by the language.

#110
  1. A variable in C++ is simply an object that has a name.
  2. In order to create a variable, we generally use a special kind of declaration statement called a definition e.g. int x;
  3. When the above statement is executed by the CPU, a piece of memory from RAM will be set aside (called instantiation)
  4. An l-value is a value that has a persistent address (in memory)… An r-value refers to values that are not associated with a persistent memory address
  5. A variable that has not been given a known value (through initialization or assignment) is called an uninitialized variable.
  6. Undefined behavior is the result of executing code whose behavior is not well defined by the language

#111
  1. In c++ programs create, access manipulate and destroy and objects. Most of the objects that we use in c++ come in the form of variables.
  2. A variable in c++ is simply an object that has a name.
  3. Instantiation is a piece of memory from RAM(random access memory) that is set aside for a specific statement or expression.
  4. i-values and r-values are completely opposite of each other. I-values has a persistent address (in memory). An r-value refers to values that are not associated with a persistent memory address.
  5. When a variable is assigned a memory location by the compiler, the default value of that variable is whatever value happens to be in that memory location at that time. An uninitialized variable is a variable that has not been giving a known value(through initialization or assignment).
  6. undefined behavior is a result of executing code that has not been well defined by the language. When code with undefined behavior has been implemented, the program may exhibit unexpected results.

#112

1. What is a variable in C++?
An object with a name.

2. What is Definition of a variable?
Specifying a type and a name for a variable for example

3. What is Instantiation of a variable?
Allocation of memory in RAM for a variable

4. What is the difference between an l-value and an r-value?
An l-value has a persistent address. An r-value hasn’t a persistent address.

5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
An uninitialized variable is in memory, but she doesn’t have value assigned to it. Using such a variable can cause unexpected behavior.

6. What is undefined behaviour?
Undefined behavior is when the result of the program may exhibit unexpected results. He can work well the three first executions and not at the fourth for example.


#113

What is a variable in C++?

  • A variable in C++ is simply an object that has a name

What is a Definition of a variable?

  • A definition is a special kind of declaration statement.

What is Instantiation of a variable?

  • When a piece of memory from RAM is set aside for the variable.

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

  • An l-value is a value that has a persistent address (in memory). Since all variables have addresses, all variables are l-values.
  • The opposite of l-values are r-values.
  • 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.

What is an uninitialised variable and what kind of behaviour can you expect from such a variable?

  • An uninitialised variable is a variable that has not been given a known value.
  • Uninitialised variables can lead to unexpected results.
  • The value assigned to an uninitialised variable is whatever (garbage) value happens to already be in that memory location.

What is undefined behaviour?

  • Undefined behaviour is the result of executing code whose behaviour is not well defined by the language.

#114
  • What is a variable in C++?

an object with a name

  • What is Definition of a variable?

a statement that creates a variable

  • What is Instantiation of a variable?

a piece of memory from RAM is referenced

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

l-value is a value that has a persistent address (in memory). Since all variables have addresses, all variables are l-values. The name l-value came about because l-values are the only values that can be on the left side of an assignment statement

An r-value refers to values that are not associated with a persistent memory address. Examples of r-values are single numbers (such as 5, which evaluates to 5) and expressions (such as 2 + x, which evaluates to the value of variable x plus 2). r-values are generally temporary in nature and are discarded at the end of the statement in which they occur.

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

A variable that has not been given a known value (through initialization or assignment) is called an uninitialized variable. It can therefore be a random value which is at the memory location assigned to variable.

  • What is undefined behaviour?

Undefined behavior is the result of executing code whose behavior is not well defined by the language. In this case, the C++ language doesn’t have any rules determining what happens if you use value of a variable that has not been given a known value. Consequently, if you actually do this, undefined behavior will result.


#115
  1. A variable is simply an object( a segment of memory )with a name.
  2. A special declaration statement to create a variable
  3. When a piece of memory is is set aside for a variable
  4. l-values have a persistent memory address whereas r-values are temporary and disappear once a statement completes execution.
  5. A variable that is assigned but not initialized is not automatically given a default value by the compiler. Therefore until it is initialized it contains garbage ie. we cannot be assured of it’s value.
  6. The result of using code whose behaviour is undefined by the language.

#116

What is a variable in C++?

  • A variable is an object that has a name.

What is Definition of a variable?

  • A variable is a value that can change.

What is Instantiation of a variable?

  • Instantiation of a variable is when you assign a variable and give it a value in the same step.

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

  • A l-value has a persistent address in memory so that values can be stored, whereas the r-value is the value to be stored.

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

  • An uninitialized variable is a variable that has not been given a known value. Using the values of uninitialized variables can lead to unexpected results.

What is undefined behavior?

  • Undefined behavior is the result of executing code whose behavior is not well defined by the language.

#117

1. What is a variable in C++?

In C++, a variable is an object that has a name. Objects are pieces of RAM memory that are used to store values. Each location, like a storage bin, has its own address, and the values of variables are stored in these locations.

2. What is Definition of a variable?

Definition of a variable is a declaration statement whereby a piece of storage is defined. Example:
int myVariable;

3. What is Instantiation of a variable?

Instantiation of a variable means to create an object.

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

An l-value is a value with a persistent address in memory. Because all variables have addresses, all variable are l/values. They are coaled l-values because they can only be on the LEFT side of an assignment statement

r-values appear to the RIGHT of an assignment statements, and are the ones NOT associated with a persistent memory addresses, such as: numbers and expressions. r-values are temporary.

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

C++ doesn’t assign a default value to an initialized variable. When a variable is assigned a memory location by the compiler, the default value will be whatever (garbage) value already exists in that location. When a variable is not given a specific value, the variable is said to be uninitialized.

6. What is undefined behaviour?

An undefined behavior is the result of executing code whose behavior is not well defined by the language. When the executed code includes an undefined variable, the results are unpredictable, unexpected, and probably incorrect. Therefore it is very important to always make sure that the variables used are correctly defined.


#118
  1. What is a variable in C++?
    Simply an object that has a name.

  2. What is Definition of a variable?
    A special kind of declaration statement that is used to create a variable.

  3. What is Instantiation of a variable?
    When a variable is assigned to a piece of memory from RAM and set aside it is called an instantiation.

  4. What is the difference between an l-value and an r-value?
    l-value is a value that has a persistent address in memory.
    r-values are generally temporary and are discarded at the end of the statement in which they occur.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    A variable that has not been given a known value (through initialization or assignment).
    C/C++ does not initialize most variables to a given value (such as zero) automatically. When a variable is
    assigned a memory location by the compiler, the default value of that variable is whatever (garbage) value happens to already be in that memory location!

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


#119
  1. What is a variable in C++?
    Object that has a name

  2. What is Definition of a variable?
    A declaration statement used in order to create a variable.

  3. What is Instantiation of a variable?
    When a piece of RAM is set aside during the execution of the variable statement.

  4. What is the difference between an l-value and an r-value?
    An l-value has a persistent address is memory. An example of this are variables. An r-value is one that is not associated with a permanent memory address. They are temporary in nature and are discarded at the end of the statement in which they occur.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    A variable that has not been given a known value (through initialization or assignment). Using the values of uninitialized variables can lead to unexpected results.

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