Variables in C++ - Reading Assignment

  1. A variable in C++ is a named object (region of storage). Its name is referred to as the Identifier.
  2. The Definition of a variable is done by declaration statement which is the process by which we create a variable.
  3. Instantiation of a variable is the process by which the object is created and assigned a memory address.
  4. The difference between an l-value and an r-value lies in that the l-value (locator value) is an object reference which occupies an identifiable location in memory. Whereas the r-value is a value or expression that does not represent an object that has a defined region of memory; i.e. is an expression which is not an l-value.
  5. An uninitialized variable has an undefined value. This can cause errors in the program which are sometimes hard to detect as the value is undefined it may cause different errors every time the program is run.
  6. Undefined behaviour is the result of executing a program whose behaviour is prescribed to be unpredictable, in the language specification to which the computer code adheres. i.e. a C++ program not behaving according to its standards.
1 Like
  1. Variable in C++ is a named object.
  2. A special kind of declaration statement used in order to create a variable.
  3. Creating an object and assigning it a memory address.
  4. An l- value is persistently defined in memory whereas r- value isn’t.
  5. An uninitialised variable is a variable that has not been given a known value and when used it can lead to unexpected results.
  6. Undefined behavior is the result of executing code whose behavior is not well defined by the C++ language.
1 Like
  1. A variable is a named region of memory.

  2. The definition of a variable is a special kind of declaration statement that is used in order to create a variable.

  3. When the program is run (called runtime), the variable will be instantiated. Instantiation is a fancy word that means the object will be created and assigned a memory address.

  4. An l-value (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address).

R-values are defined by exclusion. Every expression is either an l-value or an r-value, so, an r-value is an expression that does not represent an object occupying some identifiable location in memory.

  1. This means the variable has been defined but not instantiated. This will result in errors and common source bugs in software.

  2. Renders the entire program meaningless if certain rules of the language are violated.

1 Like
  1. variable - a named region of memory
  2. Definition of a variable - is a special type of declaration statement, defining name, value and type
  3. instantiation of a variable - when the program runs the object will be created and assigned a memory address
  4. l-value/r-value:
    5.uninitialized variable has not been initialized or assigned a value and so will take the garbage value that is in the memory location when defined.
  5. undefined behaviour - when using a variable that is not initialized will result in undefined behaviour such as bugs or other issues with the program
1 Like
  • What is a variable in C++?

A named object

  • What is the Definition of a variable?

A special type of declaration used to creating a variable

  • What is Instantiation of a variable?

The creation of a variable and assigning it a memory address

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

I-value has a memory address while R-value doesn’t

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

Uninitialized variable is a variable that has not been given a known value which creates an undefined behavior

  • What is undefined behavior?

The result of executing code whose behavior is not well defined by the C++ language

1 Like
  1. A variable in C++ 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. The definition of a variable is -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 of a variable is : When a variable is defined and assigned a value at same time e.g.
    int x = 5;
  4. Difference fo I- value and r -value is-- 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.
2 Likes
  1. A variable in C++ is a named object, the name being the identifier.
  2. The definition of a variable is a kind of declaration statement used to create a variable.
  3. Instantiation of a variable means the object (variable) will be created and assigned a memory address.
    The article did not show the answers to the following but I gathered them elsewhere…
  4. l-value is left expression used as a named reference to a memory location, and r-value is right expression evaluated for assignment purpose.
  5. An uninitialized variable is that which has been defined but not instantiated or assigned a memory address.
  6. Undefined behavior is the result of executing code that is not defined by C++ such as with bugs or incorrectly written code.
1 Like
  1. a sequence of characters that means something
  2. a variable is a named object
  3. this means creation of the variable and assigning it value
  4. l/r mean left/right value. L value is an object that persists beyond the single expression, while r-value is a temporary value.
  5. defined variable that has not been instantiated yet.
  6. executing code that is not defined by C++
1 Like
  1. A Variable in C++ is a named object.
  2. Variables are containers for storing data values.
  3. When the program is run (called runtime), the variable will be instantiated which means the object will be created and assigned a memory address. Variables must be instantiated before they can be used to store values.
    1. 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.
    1. A variable that has not been given a value is called uninitialised. 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.
  4. Executing code whose behavoir & result is not well defined os called a Undefined Behavior
2 Likes
  1. Variables are named regions of the memory holding values and other related properties.
  2. The definition is the statement that tells the compiler to reserve a portion of the memory to a specific type of data with a specific name (identifier). An example is “int myVar;”
  3. Instantiation is the assignment of a memory address to a variable at runtime.
  4. L-values are values with a specific address in memory, while r-values are values without an address in memory that, in order to be held (instead of being discarded at the end of the statement), must be assigned to l-values.
  5. Uninitalized variables are variables that have been defined without being given a known value. As result, (unless a value is assigned later on before accessing them) they grasp whatever value was already present in the memory address they have been reserved.
  6. Undefined behavior is the result of running code written in a way that produces unpredictable results (for example due to uninitalized variables).
1 Like
  1. What is a variable in C++?
    can be an integer, double, text

A variable is an object where values are stored in memory

  1. What is the Definition of a variable?

A variable is an object where values are stored in memory

  1. What is Instantiation of a variable?

When an object is created and assigned a memory address at run-time

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

  2. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    uninitialized means that it has no value. this can produce an error if use in compilation.

  3. What is undefined behavior?
    variable is undefined and has no value

1 Like

What happened to the answer to the forth question? :wink:

  1. Variables are a named region of storage (object) that can store a data value
    definition, a special kind of declaration statement that we use in order to create a variable

  2. Instantiation is a word that describes that Variables must be created and assigned a memory address, before they can be used to store values.

  3. l-values have a persistent address in memory, often represents as identifier, and appears on left hand side of an assignment operator. R-value” refers to data value that is stored at some address in memory and , can appear on right hand side.

  4. Uninitialized is a variable that has not been given a known value and can lead to unexpected results becouse if it is assigned 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 C++ language and happens when for example we use an uninitialized variable.

1 Like
  1. What is a variable in C++?

A variable is a piece of data stored and named

  1. What is the Definition of a variable?

A variable definition, instruct what kind of value we will store as a variable (ex int = integer number)

  1. What is Instantiation of a variable?

Is the process of creating the variable and save in a certain place of the memory where it can be retrieved

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

l-value is a locator value and it is assigned to a memory address.
r-value is not assigned to a memory address and are discarded at the end of the expression

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

A variable who has no value assigned. the behaviour is random and it differ if the memory slot has already been used or not.

  1. What is undefined behavior?

It can be the behaviour of a code not defined by the language

2 Likes
  1. In C++ a variable is a named object.
  2. A named region of storage that can store a data value.
  3. Instantiation is when an object is created and assigned a memory address.
  4. An l-value can be assigned a value, and an r-value cannot be assigned a value.
  5. An uninitialized variable is a variable that has not been assigned a value, and would probably return an error if it was called.
  6. Undefined behavior may refer to a variable that has not been properly assigned a storage address and may return unpredictable values.
1 Like

1. What is a variable in C++?

A named object that stores some data .

2. What is the Definition of a variable?

A definition of a variable outlines key information about a variable such as its type and name.

Example:

int number is a definition of a variable where int is the data type and number is the name of the variable.

3. What is Instantiation of a variable?

A variable is instantiated during execution of the program, bringing the variable definition to life and assigned at a location in memory.

4. 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. In general, rvalues are temporary and short lived, while lvalues live a longer life since they exist as variables. - internalpointers

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

An uninitialized variable is a variable which has no value assigned to it. It may lead to unintended consequences such as the program crashing should such variable be referenced in other parts of the program.

6. What is undefined behavior?

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

1 Like
  1. What is a variable in C++?
    A named object.

  2. What is Definition of a variable?
    It holds something in an object.

  3. What is Instantiation of a variable?
    It has a memory address assigned to it and when the compiler sees it, it knows that it is referencing to a variable.

  4. What is the difference between an l-value and an r-value?
    I-values has a persistent address while r-values do not have a persistent address.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    It is a variable that doesn’t have a value and the compiler will give it a space that can de in different places when the code runs.

  6. What is undefined behaviour?
    Code that is run and is not defined by the language.

1 Like

1. What is a variable in C++?
A variable in C++ is a named object.
2. What is the definition of a variable?
A definition of a variable is a special kind of declaratory statement.
3. What is Instantiation of a variable?
The instantiation of a variable is the creation of an object and an assigned memory address in RAM.
4. What is the difference between an I-value and an r-value?
The l-value is a value that has a persistent memory address and the r-value doesn’t have a persistent memory address.
5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
Uninitialized variables are ones that have been defined but haven’t been instantiated. This can lead to unexpected and random results.
6. What is undefined behavior?
Undefined behavior is the unexpected chaos of poorly defined code.

1 Like
  1. named object, named region of memory
  2. a declaration statement is used to make a variable.
  3. when an object is created and assigned to a memory address
  4. I-value has a persistent memory address. r-value does not have a persistent memory address.
  5. Uninitialized variable - has no value assigned to it.
  6. Undefined behavior - undefined variable without a value
1 Like

1.) Variables in C++ are named objects, which are regions of memory for the program.
2.) A definition is a declaration statement of the variable. We define a variable by giving it a name (for instance, int x;)
3.) Instantiation is when an object is created and assigned a memory address. Variables need to be instantiated before they can store values.
4.) l-values are object references and r-values are actual values. It takes an l-value argument to produce and r-value.
5.) Uninitialized variables are variables without a value. Using uninitialized variables will return ‘undefined’.
6.) When running code that is not defined (from uninitialized variables for example), undefined is returned.**
**EDIT: In C++, instead of returning ‘undefined’, the program could crash unexpectedly in random places.

1 Like