Variables in C++ - Reading Assignment

Variables are names region of storage that can store a data value

Named variable assigned to memory. Object that can store a value.

Creating and assigning a variable to a memory address.

l-value refers to a memory location which identifies an object.
r-value refers to data value that is stored at some address in memory

It’s a defined variable without a value set.

Result of unpredictable output due to code not being well defined.

1 Like

It is an object with address in memory, type, value and identifier.

It is a place in memory.

Creating the variable in the memory with a specific type and giving it an identifier which is the name of the variable.

I don’t know the answers of the rest.
I will search for answers for them later

1 Like
  1. What is a variable in C++?
    A variable is object containing a memory address, a value and an identifier by which it can be called.

  2. What is the Definition of a variable?
    It is a region of memory

  3. What is Instantiation of a variable?
    Initializing an variable by allocating a region of memory and defining a specific type and an identifier

  4. What is the difference between an l-value and an r-value?
    L-Value, can be understood like the locator value, it is the address in memory for an object
    R-Value is the actual value such as a character or a number which is stored in an address in memory

  5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    This is an variable which has not been initialized with a value. There is no value to start from. Using this variable in code without setting a value can cause undefined behavior.

  6. What is undefined behavior?
    Unpredictable output from a program due to not being well defined. Like using wrongly uninitialized variables.

1 Like
  1. Variable is basically object.
  2. Define variable means to give the variable the type and name.
  3. Creating object and assigning it to the memory address.
  4. I-Value is defined persistently in memory. R-Value is temporarily defined in memory.
  5. Variable that is defined but without given value.
  6. Unpredictable behavior. Unexpected process of program.
1 Like
  1. What is a variable in C++?
    A variable is an object, representing a memory address
  2. What is the Definition of a variable?
    The definition gives a name (identifier) to the variable and describes the type of it
  3. What is Instantiation of a variable?
    At runtime, the variable will be created and stored at a specific memory location. That’s the instantiation
  4. What is the difference between an l-value and an r-value?
    l-values are values that have their place in memory, r-values are values (or expressions) that are discarded at the end of a statement and therefore need not to be associated with a memory address
  5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    A variable without an assigned value. It’s value and behaviour is undefined. Everything could happen :slight_smile:
  6. What is undefined behavior?
    Something that you can not predict. E.g. used values could be different each time you run a program, even let’s doing the same things. Or prg could finish or crash due to an invalid behaviour
1 Like
  1. What is a variable in C++?
    A named object is called a variable.
    An object is a region of storage (usually memory) that has a value and other associated properties.

  2. What is the Definition of a variable?
    The Definition of a variable consists of a name and type.

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

  4. What is the difference between an l-value and an r-value?
    l-value has the same persistent address and the r-value is not associated with a persistent memory address.

  5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    The uninitialized variable will have no defined value, witch will cause undefined behavior.

  6. What is undefined behavior?
    Undefined behavior basically means unpredictable results.

1 Like

1. What is a variable in C++?
A named object is called a variable used to store values

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

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

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 vairable is a name given to a memory location. It is the basic unit of storage in a program. The value stored in a variable can be changed during program execution. A variable is one a name given to a memory location, all operations done on the variable effects that memory location.

  2. What is Definition of a variable?
    // A variable is a symbol used to represent an arbitrary element of a set. Variables are commonly used to represent vectors, matrices and functions.

  3. What is Instantiation of a variable?
    // A variable is initialized with a value. An Object is instatiated when memory is allocated for it and it’s constructor has been run.

  4. What is the difference between an L-value and an R-value?
    // L-value and R-value refer to the left and right side of the assignment operator. the L-value concept referst to the requirement that the operand on the left side of the assignment operator is modifiable, usally a variable. An L-value is an expression that refers to such an object. The term L-value originally referred to objects that appear on the left (hence the ‘L’) hand side of an expression. … An R-value is any expression that has a value, but cannot have a value assigned to it.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    // The value in an uninitialized variable can be anything – it is unpredictable, and may be different every time the program is run. Reading the value of an uninitialized variable is undefined behaviour – which is always a bad idea. It has to be initialized with a value before you can use it. Normally uninitialized variables are a bad idea, and the only place where they are useful is when you are about to read the variable in from some input stream.

  6. What is undefined behaviour?
    // In computer programming, undefined behavior is the result of executing a program whose behavior is prescribed to be unpredictable, in the language specification to which the computer code adheres.

1 Like
  1. What is a variable in C++? A single piece of data, stored in memory somewhere, is called a value . The value is stored in the same memory location as the object.
  2. What is Definition of a variable? A variable is a named object. The name of the object is the identifier.
  3. What is Instantiation of a variable? Declaring a variable in a specific way. Instantiation is a fancy word that means the object will be created and assigned a memory address. Variables must be instantiated before they can be used to store values. Sometimes called an instance or an instance of an object.
  4. What is the difference between an l-value and an r-value? The l-value if the identifier of the object and the r-value is the data value that is stored in the same memory address as the object. The l-value can appear on the left or the right side of the assignment operator (=), for example, int a = 1 and int b = a. The r-value appears at the right side of the assignment operator (=), for example, int x = y + 10 where y + 10 is the r-value.
  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable? The object/variable has not been given a known value either at the point of definition or per an assignment. When the object is assigned a memory location, the value will be whatever garbage is in that memory location. It can have unexpected results.
  6. What is undefined behaviour? Undefined behavior is the result of executing code whose behavior is not well defined by the C++ language. When a variable that has no known value is used the following may result: different results at runtime, consistent-incorrect results, sometimes correct result and sometimes not, program may work on some compilers but not on others, or program may work until you change some unrelated code.
1 Like
  1. What is a variable in C++? A named region of memory.

  2. What is Definition of a variable? “A named object is called a variable”. “ In order to create a variable, a special kind of declaration statement is created called a definition.” I.e.

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

  3. What is Instantiation of a variable? “It means the object will be created and given a memory address.”

  4. What is the difference between an l-value and an r-value? An l-value refers to an object that persists beyond a single expression and refers to memory location. It may appear on either the right or the left hand side of an assignment operator. An r-value is an expression that can’t have a value assigned to it which means r-value can appear on the right, but not on the left hand side of an assignment operator.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable? An uninitiated variable is a variable that hasn’t been given a value.

  6. What is undefined behavior? Unexpected, inconsistent or undesired results, which arise from using an uninitialized variable which doesn’t have any defined rules or value to determine what happens if you use the variable that hasn’t been given a value.

1 Like

Excellent answers sir, well documented! Please keep them like that :muscle:

Carlos Z.

1 Like
  1. What is a variable in C++?
    A variable in C++ is an object that is given a name. Objects are used in C++ to store and retrieve values. An identifier is the name given to the object while the named object itself is called a variable.

  2. What is the Definition of a variable?
    The definition of a variable is an object that is named and occupies a known location in memory.

  3. What is Instantiation of a variable?
    Instantiation of a variable is what happens whe a program is run. An object will be createdand given a specific memory address. This is necessary in order for a variable to store value. Another term for an object that is instantiated is an instance.

  4. What is the difference between an l-value and an r-value?
    AN l value is a locator value and occupies a specific location in memory. Originally l values in C were meant as values suitable for the left hand side of a value assignment. The const keyword came along and messed that all up.

  5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    An uninitialized variable is yet to be defined. There are two steps in order to initialized a variable. One step defines the variable and the other assigns value.

  6. What is undefined behavior?
    Undefined behavior is a result of using uninitialized variables. The outcome can be unpredictable. You never quite know what you’re going to get.

1 Like

1. What is a variable in C++?
A named object
2. What is the Definition of a variable?
A declaration statement that is used to create the variable
3. What is Instantiation of a variable?
When you run the program the variable is created and assigned a memory and an address
4. What is the difference between an l-value and an r-value?
L value has a defined region of storage, R value does not.
5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
One that has not been given a value, it will have undefined behavior
6. What is undefined behavior?
“To make demons fly out of your nose”

1 Like

Yea, this can happen :rofl:

2 Likes
  1. What is a variable in C++?
    A variable in C++ is a pointer to a memory location in the computer’s memory.

  2. What is the Definition of a variable?
    An object, region of memory, that has value that can be accessed by a program.

  3. What is Instantiation of a variable?
    This is during runtime when the program actually sets-up the variable and its value at a memory location.

  4. What is the difference between an l-value and an r-value?
    l-values point to a specific location in memory while r-value do not point anywhere and simply exist for an instant in the CPU register. r-values can be literal numbers or strings of text.

  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 the program never set-up in memory with a value and therefore does not exist in the context of the application (only as a pointer if was declared). Any function calling an uninitialized variable will likely produce error.

  6. What is undefined behavior?
    Undefined behavior is behavior that unpredictable caused by code instructions that are not valid, for example, trying to divide by 0, calling an uninitialized variable, trying to access an out of bounds index in an array. The result of these will depend on the compiler/machine but will most likely cause error when trying to compile. C++ generally allows for undefined behavior.

1 Like
  1. Variable is a named object.
  2. Definition is a statement used to create variable and to define it’s type.
  3. Variable is installed by using special kind of declaration statement called a definition.
  4. L-value describes object location in a memory and R-value stores value of the object.
  5. Uninitialized variable has no assigned initial value, so it will lead to undefined behavior.
  6. Undefined behavior is a programs error which occures due to uninitialized variable.
1 Like
  1. What is a variable in C++?

A variable in C++ is a named object.

  1. What is the Definition of a variable?

A special kind of declaration, which defines the data type of the variable and gives it a name.

  1. What is Instantiation of a variable?

An instantiation happens when an object is created and assigned a memory address. Instantiations happen during runtime.

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

L-values point to a specific memory location which identifies an object
R-values don’t point to any specific memory location, but rather refer to the data value that is stored at some address in memory.

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

It is a variable that has not been given a value yet therefore it’s value is unexpected, it can be whatever value that was previously in that memory location.

  1. What is undefined behavior?

It is the result of executing code whose behaviour is not well defined, such as uninitialised variables, this sort of behavior always lead to unexpected results.

/* I couldn't find the info for the question number 4, 5 and 6 in the given article,
 I suppose it must have been updated.*/
2 Likes

I’m not sure, to be honest I have never read the article :slight_smile: But you answered the questions correctly which means you did your own research, which is even better for you! :wink:

2 Likes
  1. What is a variable in C++?
    A named object is called a variable.
  2. What is the Definition of a variable?
    A variable is, data structured in memory, or a function in C++,
  3. What is Instantiation of a variable?
    Instantiation is a fancy word that means the object will be created and assigned a memory address. Variables must be instantiated before they can be used to store values.
  4. What is the difference between an l-value and an r-value?
    I was unable to find the answer to this question.
  5. 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 is called an uninitialized variable,
  6. What is undefined behavior?
    It is an unknown value
1 Like

Have you tried checking online? There are a lot of references explaining it :slight_smile:

It can also be other things. But most often this is due uninitialized variables containing unknown values :slight_smile:

1 Like