Variables in C++ - Reading Assignment

What is a variable in C++?
An object that has a name
What is Definition of a variable?
A declaration statement used in order to create a variable.
What is Instantiation of a variable?
The piece of memory set aside within the RAM that a statement is executed by the CPU.
What is the difference between an l-value and an r-value?
l-value has-persistent address & 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?
Is a variable that has not been given a known value; the behavior you can expect to see is your compiler will assign a random space in the memory which can change every time you run and compile the code.
What is undefined behavior?
The result of executing code whose behavior is not well defined by the language.

2 Likes
  1. A variable in C++ is an object that has a name
  2. A declaration statement used to create a variable is called a definition
  3. Reserving the needed memory (RAM) needed for a variable is called instantiation
  4. l-values (the only values allowed on the left side of an expression) are values that have a memory address. (variables is an example of l-values)
    r-values (are allowed only on the right side of an expression) are values that are temporary in nature, don’t have a dedicated memory address and are discarded after the expresion is evaluated
  5. A variable that has not been given a value is called uninitialized. The usage of such a variable leads to unpredictable results as it’s value is being taken from the memory location it has been alocated to.
  6. Executing code whoes behavior & result is not well defined os called a Undefined behavior

1. What is a variable in C++?
An object with a name used to store values

2. What is Definition of a variable?
A piece of memory that has a name and is currently defined and may be defined and vary based on another piece of memory.

3. What is Instantiation of a variable?
Defining and initializing a value in the same step.

4. What is the difference between an l-value and an r-value?
An l-value is persistently defined in memory. An r-value is not defined persistently and may be considered the variation of the l-value variable.

5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
A variable that has no memory location. We can expect anything except what we expected the variable value to be.

6. What is undefined behaviour?
The resulting value of an uninitialized variable.

1 Like

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?
A definition of a variable is special kind of declaration, where the variable is defined as a particular type that can hold a certain kind of value.

3. What is Instantiation of a variable?
Instantiation occurs when a piece of memory is set aside for a variable in RAM.

4. What is the difference between an l-value and an r-value?
An l-value is a variable that has a persistent address in memory. It is the value on the left hand side when an assignment is made.
On the other hand, r-values are not associated with a persistent memory address. They are generally 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?
An uninitialised 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 (which could be different each time it is accessed), causing unpredictable behaviour.

6. What is undefined behaviour?
Unpredictable behaviour resulting from the use of uninitialised variables, because C++ has no rules determining what happens.

1- Variable in C++ is an allocated memory space used to store a value
2- Definition of a variable is the fact to assign a name and type to a memory point address
3- Instantiation of a variable is the fact to assign a value and specific size to a defined variable
4- l-value is the left side of an assignment and r-value is the left. l-value point to the memory address which will be careful of storing the value given in r-value
5- Uninitialized variables are variables defined but not initialized whose behavior can be random because the are pointing to a point of memory address used before by the system or other program, or may be never used before, that’s random
6- Random behavior is when the program doesn’t run as you expect everytime

1. An object that has a name.

2. A declaration statement used to create a variable.

3. Reservation of memory in the RAM.

4. l-values have a persistent address in memory. r-values are not associated with a persistent memory address and are discarded at the end of the statement in which they occur.

5. An uninitialized variable is a variable that has been defined but has not been given a known value (through initialization or assignment). C++ does not initialize most variables to a given value therefore the default value of an uninitialized variable is whatever value happens to already be in the assigned memory location.

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

What is a variable in C++?
- An allocated space in memory defined by the variable name.

What is a definition of a variable?
- A placeholder for a store of value (i.e. ‘X’).

What is instantiation of a variable?
- The creation of the spaceholder in memory specifically allocated for the variable.

What is the difference between an l-value and an r-value?
- L-values are left-side variables (memory spaces) which recieve the value computed by the r-values on the right-side (the value stored within the space allocated).

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
- Uninitialized variables may produce problems if the garbage that exists in the allocated variable space gets used as valid data.

What is undefined behaviour?
- Functionality that doesn’t exist or is not properly used such that the compilers will not understand.

  1. What is a variable in C++?
  2. In C++, a variable is an object that has a name. An object is a piece of memory that is allocated to store values.

  3. What is Definition of a variable?
  4. A variable can be defined in C++ by using a declaration statement. The data type is stated, followed by the variable name.

    data_type variable_name; 
    
  5. What is Instantiation of a variable?
  6. An instantiation is a piece of memory set aside by the RAM. An instantiation is executed by the CPU after defining a variable.

  7. What is the difference between an l-value and an r-value?
  8. An l-value has a persistent address in memory. An r-value does not have a persistent address in memory. For example, the statement

    int x;
    

    vs

    int 5;
    

    The first creates a new persistent address in the memory of type integer named x. The latter does not create a change in persistent memory because the 5 is not an l-value.

  9. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
  10. An uninitialized is a variable that has not ben assigned a memory by the compiler and the default value is whatever garbage happens to be there in that memory location.

  11. What is undefined behavior?
  12. It is the result of executing code whose behavior is not defined by the language. One example is using a uninitialized variable.

2 Likes

I use it with ubuntu 14.04 without problems. Installed from software center as well.

1 Like

What is a variable in C++? is a piece of memory that can be used to store values
What is Definition of a variable? an element that is able to change
What is Instantiation of a variable? Inicialization of the variable, a piece of RAM is assigned memory location
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-value is a value that has not a persistent address in memory
What is an uninitialized variable and what kind of behaviour can you expect from such a variable? variables that have not been given a known value and C/C++ does not initialize most variables to a given value (0)
What is undefined behaviour? Using the value from an uninitialized variable

  1. Variable is a placeholder or memory location that stores value. It is an Object that has a name. It is defined as
    {type} {name} = {value};

  2. Variable is a named storage that holds some value for our program to manipulate. Varible is defined with its type and assined a value using assigment operator (=).

  3. Instantiation: When a variable is defined and assigned a value at same time e.g.
    int x = 5;

  4. l-value is Left expression and an r-value is Right expression of assigment operator in variable instantiation. l-value is used as named reference to memory location and r-value is evaluated for assignment purpose.

  5. Uninitialized variable is a variable which has been defined but not been instantiated. It is unsafe to do this as it can result in undefined and unexpected behaviour of the program.

  6. Undefined behavior is the result of executing code whose behavior is not well defined by the language. 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.

1 Like
  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
    3.When this statement is executed by the CPU, a piece of memory from RAM will be set aside (called instantiation)
  3. 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.
  4. A variable that has not been given a known value (through initialization or assignment) is called an uninitialized variable.The default value of that variable is whatever (garbage) value happens to already be in that memory location!
  5. Undefined behavior is the result of executing code whose behavior is not well defined by the language.

What is a variable in C++?
A variable is a place holder that is assigned an address and contains a value. Can anyone tell me how this is similar/different to java variables? Are primitives like int and boolean in java different than C++ variables which are more like java’s reference type Strings?

What is Definition of a variable?
A variable is a memory address (I-value) that stores information such as integers.

What is Instantiation of a variable?
Setting aside memory in RAM for a declared variable, declared in C++ by naming its type followed by an identifier

What is the difference between an l-value and an r-value?
I-values contain memory addresses in RAM and are persistent while r-values are temporary values and can only be used to do operations on.

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
An uninitialized variable has no value attached to it and can do funky stuff. C++ can assign seemingly random values to an uninitialized variable.

What is undefined behaviour?
Behavior that may appear correct because the C++ compiler allows the program to executed, but has unexpected results.

  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.

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.

2 Likes
  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
  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.
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.

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.

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.