Variables in C++ - Reading Assignment


#22
  1. A variable in C++ is simply an object that has a name.

  2. A declaration statement used in order to create a variable.

  3. When this statement is executed by the CPU, a piece of memory from RAM will be set aside.

  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. Using the values of uninitialized variables can lead to unexpected results.

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


#23

1- A statement such as x = 5; seems obvious enough. As you might guess, we are assigning the value of 5 to x. But what exactly is x? x is a variable. 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.for example: int x ,considers x as an integer variable.

3- When a C++ statement is executed by the CPU, a piece of memory from RAM will be set aside, which is called instantiation. For the sake of example, let’s say that the variable x is assigned memory location 140. Whenever the program sees the variable x in an expression or statement, it knows that it should look in memory location 140 to get the value.

4- An 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. On the other hand, 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.

5- Unlike some programming languages, C/C++ does not initialize most variables to a given value (such as zero) automatically. Thus 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! A variable that has not been given a known value (through initialization or assignment) is called an uninitialized variable. Using the values of uninitialized variables can lead to unexpected results.

6- Undefined behavior is the result of executing code whose behavior is not well defined by the language. The nature of undefined behavior is that you never quite know what you’re going to get, whether you’ll get it every time, and whether it’ll change when you make other changes.


#24
  1. A named object
  2. Memory holding the value of an object
  3. When you create a variable and give it a value upon creation
  4. r-value creates a value to assign.
  5. Who Knows, an uninitialized variable is one that didn’t specificity the value of. Your computer will do this for you create seemingly unpredictable results.
  6. The result of executing code not well defined by the language

#25
  1. a variable is an object that as a name.
  2. a special kind of declaration statement that creates a variable
  3. a certain amount of memory is reserved for this variable
  4. l values are on the left side of the assignment symbol and have a persistent address in memory. r values are on the right side of an assignment symbol and do not have a persistent address in momery. they are temporary.
  5. variables where no specific value has been assigned to. such variables hold random values so you can also expect random behvoir.
  6. executing code whose behavoir is not well defined by the language for example using an uninitialized variable.

#26
What is a variable in C++?

A variable is a value of some type (object, int, string, double) that has been given a name.

What is Definition of a variable?

This is the actual naming and instantiation of the variable (giving it an address in RAM).

What is Instantiation of a variable?

Allocating an address to the variable in memory.

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

An l-value is a value that gets a persistent address in memory, an r-value is typically an equation or some other value that can include a previously defined l-value, that is used to compute an l-value.

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 been defined, but not assigned a value. If this variable is called in this state, it will return random nonsense (in respect to our program) as it has assigned whatever was last stored in that memory location.

What is undefined behaviour?

Undefined behaviour includes program crashing, inconsistent results from program and other inconsistencies that are caused by uninitialized variables being included in the program. This is considered to be behaviour that is not well defined by the language.


#27

1-

in C++ a variable is an object that has a name and contain a single value.

2-

it is a special kinf of declaration to create a variable. 

3-

when a statement is executed by the cpu, and a variable is defined, a piece of memory from RAM will be set aside. 

4-

l-value: value that has a persistent address (in memory)
r-value: refers to values taht are not associated with persistent memory adress

5-
a variable that has not been given a known value through initialization or assigment

6-
is the result of executing code whose behavior is not well defined by the language.


#28

1. What is a variable in C++?
It is an object that has a name.
2. What is Definition of a variable?
This is a special kind of a declaration statement. E.g. int x;
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.
The key point is that on the left side of the assignment, you must have something to represent a memory address (e.g. variable) and everything on the right side will be evaluated to produce a value.
5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
This is one that not been given a value when it is first defined. Some compilers may assign it values from contents in the memory, which could lead to bugs in the code.
6. What is undefined behaviour?
It is the result of executing code whose behaviour is not well defined by the language and can result in:
• Your program produces a consistently incorrect result.
• Your program produces different results every time it is executed.
• Your program behaves inconsistently.
• Your program seems like it’s working but produces incorrect results later in the program.
• Your program crashes, either immediately or later.
• Your program works on some compilers but not others.
• Your program works until you change some other unrelated code.


#29
  1. A variable is an object (that is, a piece of memory that can store values) that has a name.
  2. A definition of a variable is a special kind of declaration statement that creates a variable.
  3. When a variable is instantiated, a piece of memory will be reserved for it.
  4. An l-value has a persistant address in memory and can be on both sides of an assignment statement, whereas an r-value are of temporary nature and do not have a persistant address; they are discarded at the end of the statement in which they occur.
  5. An variable is uninitialized if it has not been given a known value (which could happen either through initialization or assignment) yet. Using uninitialized variables lead to undefined behaviour, as virtually any value in the possible range (e.g. 0-255 for an unsigned 8-bit variable) could be in it.
  6. Undefined behaviour appears when executing code that is not well defined by the language.

#30
  1. A variable is just an object that possesses a name.
  2. The definition of a variable is a special kind of declaration statement.
  3. The instantiation of a variable is when the computer assigns a memory location to that variable.
  4. An (ell)-value is a value on the left side of the assignment operator. It has a persistent memory location. The r-value is a value of which does not have a persistent memory location and can be discarded. Something like a number or expression could be an example.
  5. An uninitialized variable is a variable that has been given a memory location but no value. If you try and print its value, you will not know what it spits out.
  6. Undefined behavior is when code that is executed is not well defined by the language. It may produce inconsistent results or just simply not work.

#31

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

2. What is Definition of a variable?
In order to create a variable, we use a special kind of declaration statement called a definition. For example: int x;

3. What is Instantiation of a variable?
The instantiation is a piece of memory from the RAM, which is set aside 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. All variables in C++ are l-values. An r-value is a value which is not associated with a persistent memory address such as single numbers and expressions. R-values 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 is uninitialized.

6. What is undefined behavior?
Undefined behavior is the result of executing code whose behavior is not well defined by the language. For example, in C++ if you use a variable that has not been assigned a value, it can lead to undefined behavior because we do not know what is contained in the allocated address in memory. Undefined behavior can include: incorrect results, inconsistent results, a crash, incompatibility with certain compilers etc.


#32

1. What is a variable in C++? If you think of an object as a piece of memory that’s used to store values then a variable is just an object with a name.

2. What is Definition of a variable? A statement that specifies the name and type of that variable.

3. What is Instantiation of a variable? Refers to the process of allocating some memory to a variable.

4. What is the difference between an l-value and an r-value? An l-value is a value that has a persistent memory address whereas r-values do not.

5. 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 yet to be given a known value that when used, can cause unexpected results because the value it holds is just whatever value that happens to be residing in that memory location.

6. What is undefined behaviour? Undefined behaviour is the result of executing code whose behaviour is not well defined by the language, which leads to inconsistent behaviours and results.


#33

What is a variable in C++?
- A variable is simply an object that holds a value in c++.
What is Definition of a variable?
- Definition of a variable tells the program what type of information the variable will contain.
What is Instantiation of a variable?
- Instantiation is the piece of memory that a variable gets stored in.
What is the difference between an l-value and an r-value?
- l-values are already defined and r-values will be evaluated.
What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
- Uninitialized variables are variables that have not been assigned a value. The program will not know what to do with it.
What is undefined behaviour?
- Undefined behaviour happens when the code has not defined what to do with a variable, it can result in the program not executing properly.


#34

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.


#35
  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.

#36

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.


#37

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.


#38
  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.

#39
  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.

#40

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


#41

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)