Variables in C++ - Reading Assignment

  1. What is a variable in C++?
    Named object.

  2. What is Definition of a variable?
    A variable is a named region of memory.

  3. What is Instantiation of a variable?
    The object will be created and assigned a memory address.

  4. What is the difference between an l-value and an r-value?
    An l-value always has a defined region of storage, so you can take its address. An r-value is an expression that is not an l-value.

  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++ does not initialize most variables to a given value automatically. When a variable is assigned a memory location by the compiler, the default of that variable is whatever value happens to already be in that memory location.

  6. What is undefined behaviour?
    Result of executing code whose behavior is not well defined by the C++ language.

1 Like

What is a variable in C++?
A variable is an object with a name. Since an object is is a region of the storage with with value and properties, so the variable has.

What is Definition of a variable?
A variable is a defined type of data, stored in a region, with a specific value and name.

What is Instantiation of a variable?
Instantion is the process that allocates variables and its properties to specific areas of memory when the program starts.

What is the difference between an l-value and an r-value?
l and r refer whether the variable is on the left or right side of the equation. An l value is usually what we call as variable (a = 3) which has an allocation in memory in this case it’s an integer with value 3. As r values aren’t stored anywhere if we don’t assign them a place. In summary think of a box l-value and what you put in the box r-value.

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
An unitiazed variable is a defined variable, but to who we didn’t defined any value. The problem here is that everytime we compile our program we never know what value is inside.

What is undefined behaviour?
Undefined behaviour appear when we don’t have the consistent results running the program over and over again, it crashes the program or goes into loop, works only on some compilers and it starts working when we change something that had nothing to do about the error we were getting.

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

  2. What is the Definition of a variable?
    variables are containers for storing data value

3.What is Instantiation of a variable?
Is the memory address of the object

  1. What is the difference between an l-value and an r-value?
    In C++ an lvalue is something that points to a specific memory location. On the other hand, a rvalue is something that doesn’t point anywhere. A variable has a specific memory location, so its an lvalue. C++ states that an assignment requires an lvalue as its left operand, this is perfectly legal.

5.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 value by the program (generally through initialization or assignment). Using the value stored in an uninitialized variable will result in undefined behavior

  1. What is undefined behavior?
    Occurs when a program does something the result of which is not specified by the standard or language.
2 Likes

1 - A variable is a reference to a memory location (an object)

2 - A definition of a variable is a name and a type which is then assigned a memory location

3 - Instantiation of a variable is programmatically assigning a name, type and memory location to the variable

4 - l-value is an object reference and r-value is a value without an address

5 - An uninitialized variable is a variable that is referenced before being assigned a value - this will cause unpredictable behavior

5 - Undefined behavior is the result of something syntactically (so not caught by the compiler) but will result in unpredictable behavior from the program

1 Like

1- A variable is a named region of memory.

2- A single piece of data stored in RAM is called value. In C++ direct memory access is not allowed. Instead, we access memory indirectly through an object. When an object is named, it is called as variable. And its name is called as identifier.

int x;

int x -> defining a variable named x
int -> type
x -> identifier

3- Instantiation of a variable means that the object will be created and assigned a memory address. Variables must be instantiated before they can be used to store values.

4- An object is a region of memory that can be examined, but not necessarily modified. An lvalue is an expression that refers to such an object. An rvalue is any expression that has a value, but cannot have a value assigned to it. An rvalue is any expression that is not an lvalue

5- A variable that has not been given a known value is called an uninitialized variable. This variable can lead to undefined behavior.

6- Using the value from an uninitialized variable is undefined behavior.

1 Like
  1. A named region of the memory.
  2. A named region in the memory.
  3. Instantiation of a variable is the process of creating it and storing it somewhere in memory.
  4. l-value points to a specific location in the memory, while r-value doesn’t have a space in the memory.
  5. When a variable is uninitialized, it doesn’t have a value assigned to it, which can cause unexpected things.
  6. It is de unpredictable thing, that happens, when using an uninitialized variable.
1 Like
  1. A named object.
  2. A kind of declaration statement used to create a variable.
  3. Creating and assigning a memory address to an object.
  4. l-values are values that have their place in memory, r-values are values that are discarded at the end of a statement and therefore need not to be associated with a memory address
  5. Uninitialized variables haven’t been given a value and can cause unexpected behavior.
  6. Behavior that causes unexpected results.
1 Like
  1. What is a variable in C++?

In C++, a variable is an object that holds a piece of data in a particular area of the computer’s memory. A variable allows the user to store data in a particular area of the computer’s memory, to indirectly access that part of the computer’s memory at a later point in time and retrieve the data that is stored there.

  1. What is the definition of a variable?

In C++, a variable is defined as a named object. The name of the object, i.e. the variable name, is called identifier.

The syntax to define a variable is writing the data type of the variable followed by the variable name. The variable definition statement is closed by a semicolon.

int a; // defines the variable "a" of the type integer
  1. What is instantiation of a variable?

During the runtime of a program, a variable that has been defined as per the program’s code will be created and assigned a memory address which is the area where the variable’s value is stored and where it can be retrieved when the variable is called. A variable must be instantiated before it can be used to store values. An instantiated variable is also called an instance.

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

The l-value is an object reference and the r-value is simply a value that is assigned to the l-value. Being an object reference, the l-value has an address in the computer’s memory, while the r-value is simply a value that does not have a memory address.

  1. 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 been defined but not yet been assigned a specific value. As such, it is assigned a memory address but no corresponding value. However, calling an uninitialized variable can result into undefined behavior because the variable, although it has not yet been assigned a value, will hold the default value of the memory location it was assigned to. This value may change every time the variable is called and thus it is unpredictable what output it will generate when called.

  1. What is undefined behavior?

Undefined behavior is the outcome of running code in C++ that is not well defined. The generated output of such code is unpredictable and it may vary every time the code is run. Therefore, it is something that a programmer must prevent from occurring.

2 Likes
  1. a variable is an object with a name

  2. the line in the code where you define the creation of a new variable.

  3. the creation of an object and its assignment to a place in the memory while running the program is called instantiation.

  4. The words “l-value” and “r-value” are not used in the article. However I found a good explanation: the l-value is the memory allocation of the object, and the r-value is the value stored in the memory address assigned to the object. Example:
    int a = 4; -> “int a” is the l-value (on the “left side” of the statement) and “4” is the r-value (on the “right side” of the statement).

  5. an uninitialized variable is one that has not yet a value assigned to it. If not used after the statement nothing happens. If used in a calculation it seems to produce a random result (as later is also being confirmed in chapter 1.6 in the cpp tutorial).

int main()
{
    int a;
    int b=5;
    int c=a+b;
    cout << c;
    return 0;
}
  1. An undefined behavior is when your program’s results are not what they are expected to be, for some reasons you might not have been thinking about. It can crash, it can return false results,…
2 Likes
  1. What is a variable in C++?

A variable is an object that acts as a named region of memory.

  1. What is the Definition of a variable?

The definition is a declaration statement in the variable that holds a value.

  1. What is Instantiation of a variable?

When an object is created and assigned to a memory address.

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

An l-value is a value that’s located in memory and is addressable while an r-value is a temporary value without a place in stored memory because they are disregarded after the expression on the l-value is evaluated.

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

A variable that has not been given a known value

  1. What is undefined behavior?

Code that is executed without a predictable pattern

1 Like

FORUM QUESTIONS

  1. What is a variable in C++?
    A variable is a named object which has been declared in a program and is able to have some value assigned to it. A variable sits in the computers memory, such that when the program calls upon the variable, the compiler will know where to look in the memory and retrieve the value assigned to that variable.
    Variables are particularly useful for human readability. Some of the first versions of computers and functional programs were able to store values, however they were called upon by an index of numbered memory blocks. So if a programmer wanted to utilise some value saved to the memory, they would have to call upon memory block ‘432’ for example, as opposed to userAge.

  2. What is Definition of a variable?
    The definition of a variable is made when the programmer first introduces the variable to the program. When they do this, they have to explicitly tell the computer what type of variable it is, along with the identifier (or name) of the variable.
    So, a type could be an integer, a string, a number etc. The definition tells the computer the type, and the name, for example: int userAge;

  3. What is Instantiation of a variable?
    Instantiation of a variable occurs when the the program assigns some piece of memory to store it. So when a program is run, the computer will look at the variables and instantiate it to so memory location (e.g. memory location 235). So when the program calls upon the variable, it know to go look in memory location 235.

  4. What is the difference between an l-value and an r-value?
    An l-value is the memory location which identifies an object. This means that they are most commonly the identifier of a variable.
    An r-value is the data that is stored at some place in the memory.
    An l-value can only be on the left or right hand side of the = operator, however an r-value may only appear on the right hand side.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    An uninitialized variable is one that has been declared by a definition, such that the variable has been allocated a spot in the computers memory, however, no value has been assigned to the variable.
    If you were to call an uninitialized variable, the program will spit out an unpredictable output. As no value has been set, it will return a value which was the default of the memory location in which the variable sits in.
    This means it could very likely produce different results each time you run the program.
    This is known as undefined behaviour.

  6. What is undefined behaviour?
    Undefined behaviour takes place when there exists a lack of consistency in the output between iterations of running a program. In other words, some variable has not been defined, and as such the computer will output a value which is the default for the memory location in which an uninitialized variable sits in. And this default value changes regularly.

ARTICLE QUESTIONS

  1. What is data?
    Data is information that can be used by a computer. This information can be stored, manipulated and calculated by a computer to produce desired results.

  2. What is a value?
    A value is some piece of data that has been assigned to a variable and stored in the computers memory.

  3. What is a variable?
    A variable is an identifiable value that has been placed into the computers memory to be called upon by a program. Instead of having to understand each memory locations number in the computer, a programmer can initialize a variable and call it by a more appropriate name. When a program calls the variable, the computer knows which memory location to look for the desired value.

  4. What is an identifier?
    An identifier is a variable’s name. So the program could call the identifier of a variable, and the computer will know which memory location the variable was assigned to look in to retrieve the variable’s value.

  5. What is a type?
    The type of the variable is the DNA characteristic of the variable so that the computer knows how to treat it. If the variable is going to be an integer, the programmer must identify so when the variable is defined. If the variable is to be treated as a string, the program will be required to initialize it as so, and therefore not treat it as a number, for example.

  6. What is an integer?
    An integer is a whole number without some fractional component. An integer cannot be a decimal or word.

1 Like
  1. a named object
  2. a memory location for holding a value for an object
  3. assigning a value on creation
  4. l-value is the assignee, r-value is an expression that determines the value to assign
  5. declared but not instantiated, behavior is unpredictable
  6. may work, may not , could be consistently wrong result, could be inconsistent, may appear to work but cause downstream bugs
1 Like

What is a variable in C++?
Is an “object” with an identifier (name) and a content of a certain type. An object is a region of storage (usually memory) that has a value and other associated properties. Generally speaking you can imagine a box with a label (name) and some content (pens for example)

What is Definition of a variable?
You define a variable name (identifier) and type with a TYPE Identifier syntax
Here’s an example of defining a variable named x:

int x; // define a variable named x, of type int

What is Instantiation of a variable?
Do you mean initialization of a variable? In this sense it means assign a value to the variable.

What is the difference between an l-value and an r-value?
l_val = r_val
In this expression r_val is assigned to l_val.

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
It’s a var to which has not been assigned a value, so it’s value it’s not known. You can have undefined behaviour.

What is undefined behaviour?
Since you can’t tell the value of an uninitialized variable, the program can have a undefined behaviour.

2 Likes
  1. Objects can be named or unnamed (anonymous). A named object is called a variable.
  2. Is an expression saying what type the variable is and what is its name.
  3. Means the object will be created and assigned a memory address.
  4. An l-value is a value that has a persistent memory address and an r-value is a value that doesn’t have a persistent memory address.
  5. A variable which hasn’t been given a known value via initialization or assignment. Expect unexpected results from such a variable.
  6. Undefined behavior is the result of executing code whose behavior isn’t defined by the language.
1 Like

1. What is a variable in C++?
A variable is a named region of memory in which data is stored.

2. What is the Definition of a variable?
The definition of a variable is the process of writing out the name of the variable as well the datatype of the variable, such as -> int myInt;

3. What is Instantiation of a variable?
Instantiation of a variable is the process of assigning a defined variable a memory location.

4. What is the difference between an l-value and an r-value?
l-value is an object that represents some identifiable location in memory.
An r-value is a object that does not represent some identifiable location in memory.

5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
It is a variable that has not had a value assigned to it by the programmer. The variable has been declared but not been assigned a value in the program it is meant to be used.

Such uninitialized variables will have garbage values contained within after the compiler assigns a memory location to them (instantiation); the garbage value will be whatever random value is in the memory location.

6. What is undefined behavior?
Behaviour that is not defined by the C++ language.

2 Likes
  1. A variable is a named object.

  2. It is a declaration statement used to create a variable.

  3. When the program is run, the variable is instantiated. This means the object is created and assigned a memory address.

  4. An l-value has an identifiable memory address and an r-value does not.

  5. An uninitialized variable is a variable that has not been given a known value. The default value of an uninitialized variable is whatever value happens to already be in the memory location it is given. Using the value of an uninitialized variable can lead to undefined behavior.

  6. Undefined behavior can occur when executing code that is not well defined by the C++ language. Some examples of undefined behavior are:

-Program produces different results every time it’s run.
-Program consistently produced incorrect result.
-Program crashes.

1 Like

Questions:
. Variables are named objects with an identifier.
. Definition is a particular type of declaration which includes giving an integer value to a variable.
. Instantiation involves creating an object and giving it a memory address so that values may be stored.
. The r value is the data value stored in the memory while the l value is a memory location.
. Variables which are not set to a specific value and are unpredictable.
. The result of when a program is executed with unpredictable results when a variable is uninitialized.

1 Like
  1. In C++, a variable is a named object that is used to store values.
  2. A definition of a variable is a declaration statement used to create a variable, for example int x; which defines a variable x of type int.
  3. Instantiation of a variable is where the object is created and assigned a memory address, this must happen before a variable can be assigned a value.
  4. An l-value is something that points to a specific memory location, as where an r-value is something that doesn’t point anywhere. For example with int x = 777; x is an l-value as it points to a memory address and is a variable, and 777 is an r-value since it doesn’t point anywhere. R-values are short lived if they are not contained in an l-value.
  5. An uninitialized variable declared but not instantiated, so it hasn’t been given a value yet. The behavior of such a variable is unpredictable.
  6. Undefined behavior is where there are no rules in C++ that determine what will happen with the code that is executed, and the results are completely unpredictable.
1 Like
  1. A named object is called a variable

  2. A variable is a storage inside a memory that holds a value

  3. The variable is assigned a value

  4. L-value: Variable with a identifiable memeory location
    R-value: Variable without a identfiable memory location

  5. A variable that has not been given a value is called an uninitialized variable. Using the values of uninitialized variables can lead to unexpected results.

  6. Means running a program may not have a expected outcome

1 Like
  1. What is a variable in C++?
    A variable is a name of memory location. It is used to store data. Its value can be changed, and it can be reused many times.

  2. What is Definition of a variable?
    A variable is a name of memory location. It is used to store data. Its value can be changed, and it can be reused many times.3. What is Instantiation of a variable?

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

  4. What is the difference between an l-value and an r-value?
    An L-value represents an object that occupies some identifiable location in memory while an R-value is defined by exclusion and is only considered as an expression because it does not represent an object occupying some identifiable location in memory.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    No attached value… Resulting undefined and unexpected behaviour.

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

1 Like