Variables in C++ - Reading Assignment

  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.

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

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.

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.

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.

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.