Variables in C++ - Reading Assignment

1. What is a variable in C++?
It is an object which is a piece of memory, has a name and stores a value.
2. What is Definition of a variable?
It is the creation of a variable.
3. What is Instantiation of a variable?
It is the assignment of a piece of memory from RAM to a variable.
4. What is the difference between an I-value and an r-value?
An l-value is a persistent address in memory, otherwise a r-value is not associated with a persistent memory address. r-values can be numbers or expressions.
5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
It is a variable which was created but its value is not defined yet and could be garbage according the compiler. An uninitialized variable could lead to unexpected results.
6. What is undefined behavior?
It is the result of executing code whose behavior is not well defined by the language. We never know what we are going to get.

  1. A variable in C++ is a piece of code or object that has a name and is used to store a value.
  2. Definition of a variable means creating a variable and defining it as a type.
    3.Instantiation means that the CPU’s RAM has set aside a place in its memory to store the value of a variables at that location.
  3. An l-value is a value with a persistent address in the memory, an r-value is a value not associated with a persistent address f.e. a single number
  4. An uninitialized variable hasn’t been given a known value through initialization or assignment, which can give unexpected results.
  5. Undefined behavior occurs when you execute code that isn’t well defined. You never know what you’re going to get.

What is a variable in C++?

It is an object that has a name

What is Definition of a variable?

It is a value that has a persistent address in memory

What is Instantiation of a variable?

It is the process where memory is set aside to hold a variable value to be assigned later.

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

l-value has an adress in memory where values can be stored, r-value do not have a persistent memory address.

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

Uninitialized variable is a variable with no value assigned to it, the behaviour is unreliable as any “garbage” in memory will be its value

What is undefined behaviour?

Undefine behavior means the language in this case C++ does not have rules on how to handle such situations and the results cannot be predicted or expected to go in the way originally intended.

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

2. What is Definition of a variable?
Using a declaration statement to create a variable.

3. What is Instantiation of a variable?
After the CPU executes a declaration statement defining a variable, the CPU then sets aside a piece of memory from RAM for the variable.

4. 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). An r-value refers to values that are not associated with a persistent memory address

5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
C/C++ does not initialize most variables automatically. So you can instantiate a variable without knowing for sure what value it may hold. Expected behavior is randomness and high chance of error and issues with your code.

6. What is undefined behaviour?
Undefined behavior occurs when the program implements code whose behavior is not well defined by the language. When code with undefined behavior is implemented, the program may exhibit unexpected results.

  1. Variable is an object that has a name.
  2. The variable definition is a declaration statement.
  3. Instantiation of a variable is the execution of the statement by the CPU, the variable is assigned in a memory location.
  4. An l-value is a value that has a persistent address (in memory) and is on the left side of an assignment statement.
    An r-value refers to values of expressions on the right side of the assignment, r-value is not associated with a persistent memory address and is generally temporary in nature.
  5. The uninitialized variable has no value which can lead to unexpected results.
  6. Undefined behavior is the result of executing code whose behavior is not well defined by the language.
  1. Variable is an object.
  2. We define it by giving type and name.
  3. Allocation of memory for the variable.
  4. r-value is temporary value and gets used before final result is assigned to l-value.
  5. It is a variable with undefined value.
  6. We can not predict how the program behaves.

What is a variable in C++?
is simply an object that has a name
What is Definition of a variable?
In order to create a variable, we generally use a special kind of declaration statement called a definition
What is Instantiation of a variable?
hen a statement is executed by the CPU, a piece of memory from RAM will be set aside (called instantiation)
What is the difference between an l-value and an r-value?
An l-value is a value that has a persistent address / An r-value refers to values that are not associated with a persistent memory address
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. 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!
What is undefined behaviour?
Undefined behavior is the result of executing code whose behavior is not well defined by the language

Variables in c++

  1. A variable in C++ is a named Object.

  2. The definition of a variable is the whole statement you need to declare ex. int x = 3;
    It specifies a data type. the definiton tells the compiler where and how much storage to create in your RAM (Random Acces Memory)

  3. When this statement is executed by the CPU, a piece of memory will be assigned to this variable (location in RAM)

  4. L-value is always left of the assignement operator (=). all variables are L-values. It has always an adress in memory. R-values are not associated to a memory location, because they are temporarly (only in its statement). r-values are expressions, numbers, ..
    L-value = r-value + r-value ; // = definition

  5. Uninitialized variables are variables who arent declared or assigned a value. (not automatically zero) If you dont assign a value, the memory location contains a value already from something else. this can be anything. so it can behave unpredictable (undefined behavior)

  6. The execution of code whose behavor isn't defined by c++ can produce incorrect results, inconsistentily, can crash,... maybe if you are lucky it can run one time (if there was accidentily the right value in it)

  1. What is a variable in C++?

A variable in C++ is an object, i.e. a piece of memory, with a name associated to it.

  1. What is Definition of a variable?

The Definition of a variable is a statement that when executed will trigger the Instantiation of said variable.

  1. What is Instantiation of a variable?

The Instantiation of a variable consists in setting aside a piece of memory associated to this variable.

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

A l-value is associated with a persistent memory address while a r-value isn’t.

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

An uninitialized variable is a variable that has not be given any value after being defined. The variable is associated to a piece of memory and its value is then whatever resides in that piece of memory.

  1. What is undefined behaviour?

An undefined behaviour is the result of executing a piece of code that has no defined behaviour in the language.

  1. What is a variable in C++?
    

A chunk of memory allocated in RAM

  1. What is Definition of a variable?
    

defining it’s name and it’s data type

  1. What is Instantiation of a variable?
    

giving a value to a variable

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

l-value stays in memory, r-value is temporary and discarded after it’s used

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

a variable that has not had a value assigned to it, your program most likely won’t compile

  1. What is undefined behavior?
    

odd behavior that happens when an uninitiated variable is used.

  1. A variable in C++ is simply an object (a place in memory) that has a name.
  2. A definition is a declaration statement used to create a variable.
  3. Instantiation is setting aside memory in RAM (for a variable)
  4. An l-value is a value that has a persistent address (in memory). An r-value refers to values that do not have a persistent address in memory.
  5. An uninitialized variable is a variable which has not been assigned a value in the program. Undefined behaviour may result from this.
  6. Undefined behavior occurs when the program implements code whose behaviour is not well defined by the language. When code with undefined behaviour is implemented, the program may exhibit unexpected results.

What is a variable in C++?
A name that identify a value in memory

What is Definition of a variable?
A statement to define a variable

What is Instantiation of a variable?
Give a name to a memory address

What is the difference between an l-value and an r-value?
l-value has space in memory (variables)

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
It is a variable without assignment, and this can lead to undefined behavior because the variable can take any value.

What is undefined behaviour?
Behavior that is not defined by the language and can lead to unexpected situations.

What is a variable in C++?
simply an object that has a name.

What is Definition of a variable?
specifying a variable and declaring its type.

What is Instantiation of a variable?
defining and assigning a value to a variable.

What is the difference between an l-value and an r-value?
l-value has a permanent location in memory - usually the left side of an assignment.
r-value is not permanent in memory and is discarded after use… usually on the right side on and assignment.

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
int x;
this variable points to a location in memory and that memory contains whatever was previously there.

What is undefined behaviour?
is the result of executing code whose behavior is not well defined by the language. an example of this is an unintialized variable.

1. What is a variable in C++?
It’s an object that has a name and through this name is possible access a piece of memory where this object is storage.

2. What is Definition of a variable?
It’s an special kind of statement that create a variable.

3. What is Instantiation of a variable?
When a definition statement is executed, a piece of memory from RAM is reserved and the address of this piece is linked with the variable.

4. What is the difference between an l-value and an r-value?
An l-value has a persistent address like all variables, whereas r-value is the value that are not associated with the persistent memory address.

5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
It’s a variable that has not been given a known value through initialization or assignment. An uninitialized variable can has any value hold in piece of memory allocated for it, these way, this kind of variable can result an undefined program behavior.

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

What is a variable in C++?
variable is an object that has a name
What is Definition of a variable?
definition is a special kind of declaration statement that we use for create a variable. we need to define a type a of a variable and its name ( int a; )
What is Instantiation of a variable?
instantiation is reserving a part of memory for our variable.
What is the difference between an l-value and an r-value?
l-value represents a memory address. it is on the left side of the assignment operator. r-value is value assigned to a variable (l-value) and it is on the right side of the assignment operator.
in example y=3; a is l-value (variable) and 3 is r-value assigned to a variable y.
What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
it is a variable without a value. every time we run the program, our variable has a different value. modern compiler can write warning that we didn’t initialize a variable.
What is undefined behaviour?
it is when something in the code is not well defined. i.e. uninitialized variable

  1. A variable is an object with a name
  2. Declaration of a variable is called as defining the variable eg: int x
  3. Instantiation of a variable is assigning some address to variable in the memory
  4. I-value is the persistent value it remains when it’s created whereas r-value is the temporary value which is created only for that moment and vanishes later
  5. A uninitialized variable is the one which has a variable whose value is not assigned but it has a garbage value which creates an error when later referred in the code
  6. An undefined behavior causes an unexpected feature in the program or it creates uncertainty in the program like an uninitialized variable.

What is a variable in C++?
a variable is a name for an object that can contain something (for example a string)
What is Definition of a variable?
Defining a variable means that we tell the program that we want to use it so we have to create it first
What is Instantiation of a variable?
a piece of the memory is assigned to that variable
What is the difference between an l-value and an r-value?
all l-values have a memory address assigned, so all variables are l-values. r-values are not assigned to a memory address and are temporarily needed while executing a statement to hold some temporariy value before it is assigned to a variable.
What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
This is a variable that did not get a default value when you create is. You never know what you will get from that variable since it just returns whatever is inside the mem adres it gets allocated to.
What is undefined behaviour?
All kinds of behaviour of a program that the language doesn’t know what to do with is (not defined in the language)

What is a variable in C++?
A variable it is simply an object that has a name. That name points precisely to a
part of the memory.

What is Definition of a variable?
Give it a name so that it is allocated in a specific part of the memory. For instance
int x;
defines a variable, but it is not initialized.

What is Instantiation of a variable?
Create a variable AND give it an initial value. For instance
int x=5;
initialized the variable x with the initial integer value of 5.

What is the difference between an l-value and an r-value?
l-values are permanent allocations in the memory while r-values just last for the time they are used to perform the (righthand side of the) code they are in.
Thinking back to the lecture, I imagine r-variables are allocated in the MEMORY and r-variables are allocated in the ALU (arithmetic logic unit).

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
It is a variable that is defined but it is not given right away a value. Such variables are troublesome because although they are not GIVEN an initial value, the value that they have
happens to be the last value that the memory “remembers” for them.
Since you do not control the value of an uninitialized variable, the code runs with whatever the value happens to be at that time and can result in:
(a) wrong answer.
(b) right answer, but sometimes, not always.
© the code might work with some compilers and not others.

Since many things can go wrong, such variables are difficult to debug.

What is undefined behaviour?

Is the result of running code with uninitialized variables.

Quiz
My answers:
Ans1. 3
Ans2. 3
Ans3. 6
Ans4. 3
Ans5. whatever happens to be in the memory that z points to.

1. What is a variable in C++?
Variable in C++ is an object which has a name.
2. What is Definition of a variable?
Is an expression saying what type the variable is and what is its name.
3. What is Instantiation of a variable?
Instantiation is setting the variable a value.
4. What is the difference between an l-value and an r-value?
l-value has a persistent address in memory and the r-value is not assigned with the persistent address in memory.
5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
Uninitialized variable is the one which has not been given a value. Such variable has not assigned a space in memory and it can lead to undefined behavior.
6. What is undefined behavior?
Undefined behavior is the result of executing the code whose behavior is not specified by the language.

  1. A variable is an object (which is a place in memory where data can be stored) that has a name.
  2. Definition of variable is when the variable is simply declared with its type so the required memory is allotted for it but no data is stored into it.
  3. Where the variable is given its memory location.
int x; // instantiation
  1. l-value is the value which has persistent memory address and values can be assigned to it.
    r-value is the value which doesnt have persistent memory address and is used during evaluation and then discarded.
  2. Variable which hasn’t been given a definite value to hold in the program. Undefined behaviour is expected.
  3. Where the outcome is undefined.