Variables in C++ - Reading Assignment

  1. What is a variable in C++?

A named object

  1. What is Definition of a variable?

A variable is a declaration statement used to create a variable.

  1. What is Instantiation of a variable?

Means the object will be created and assigned a memory address

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

l-value is an object reference whereas r-value is a value.

  1. 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 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 behaviour?

Undefined behaviour occurs when a program does something the result of which is not specified by the standard.

1 Like

1.) A named object is a variable.
2.) Definition is the use of a declarative statement to create a variable.
3.) Instantiation means that an object will be created and a memory address.
4.) An I-value has an address, and an R-value doesn’t.
5.) An uninitialized variable is one that hasn’t been assigned a value, often leading to undefined return.
6.) undefined behavior happens when the program isn’t running well within the parameters of the language it’s written in.

1 Like
  1. A variable in C++ is a named object(or named region of storage).
  2. Variable definition is a special kind of declaration statement that creates a variable.
  3. Instantiation of a variable means the object will be created and assigned a memory address at runtime.
  4. An l-value(could appear on the left side of an assignment expression) designates an object or a function; an r-value(could appear on the right side of an assignment expression) is an x-value(an object, usually near the end of its lifetime), a temporary object or subobject thereof, or a value that is not associated with an object.
  5. An uninitialized variable means the object(variable) has not been given a known value yet(the default value of that variable is whatever value happens to already be in that memory location), 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 C++ language. For example: Using the value from an uninitialized variable.
1 Like

1. What is a variable in C++?
Its is a named Object

2. What is the Definition of a variable?
Definition is a declaration statement for example it makes a note to itself that we are defining a variable, giving it the name x , and that it is of type int

3. What is Instantiation of a variable?
It is the creation and assignment of a memory address, they need this so they can be used to store values

4. What is the difference between an l-value and an r-value?
An r-value is a variable without an address, but as you write it can only be used in order to assign value to an l-value

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 through initialization or assignment is uninitialized variable. When this happens we can expect the computer to assign some unused memory to X

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

1 Like
  1. A variable in C++ is a region in memory

  2. It’s the operation of writing the statement/line of code that will create the variable when the program is run.

  3. it’s operation of actually creating the variable which will occur at runtime

  4. l-values identify the values on the right side of an expression and ha ve a memory address while the right value is the assigned value.

  5. An uninitialized variable is in memory, but doesn’t have an assigned value. Since it was assigned a memory address, if accessed it will return any (random) value that had previously been stored on that memory address.

  6. It’s the result of the execution code whose behavior is not predicted by the C++ language rules. You basically (might) get unpredictable results when running code that has “undefined behavior” issues.

1 Like
  1. What is a variable in C++?
    A variable is a named region of memory to use in an algorithm.
  2. What is Definition of a variable?
    Is telling the name and value type fr this memory space.
  3. What is Instantiation of a variable? Is giving it initial value
  4. What is the difference between an l-value and an r-value? In instantiation, Left value is the memory space or destination for the right side value, the information to store.
  5. ***What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    *** declared but not instantiated, behavior is unpredictable because the previous value in memory address is used. If the address was a schar or string, declaring an int gives you ASCII value f that character.
  6. What is undefined behaviour?
  7. Undefined behavior is the result of executing code whose behavior is not well defined by the language. It won’t always do an error but 2x3+4 may be 10 or 14 depending if the priorities are considered or not.
1 Like

Answers

  1. A variable in C++ is a named object.

  2. Definition of a variable is a declaration statement used to create a variable.

  3. A instantiation of a variable is when the object will be created and assigned to a memory address.

  4. A I-value has a persistent address in memory and is the value on the left hand side when the assignment is made. The R-value are not persistent memory address, rather they are temporary and are discarded at the end of a statement.

  5. A uninitialized variable has no memory location, it will have some value but not a predictable one.

  6. An undefined behavior means anything is allowed to happen in the program execution.

1 Like

In C++ this will be executed in order as math defines it (prioritizing multiplication to addition). But its true in some languages you have to be careful about the order of math operations. Though I wouldn’t consider this as undefined behavior its still according to the rules the language has defined. :slight_smile:

1 Like

1.a named object
2.using a special kind of declaration statement.
3.created and assigned a memory address.
4. l-values have a persistent address in (memory space). R - are not with a persistent memory address and also discarded at the end of a statement in which occur.
5.variables may produce problems if the garbage that exists in the variable space gets used as valid data.
6.Using the value from an uninitialized variable

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

A variable is a named object

  1. What is the Definition of a variable?

a variable’s definition is the declaration statement used to create it

  1. What is Instantiation of a variable?

it is the creation of the variable by the computer when the program is run. A place is prepared for the variable in the memory when it is instantiated

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

an l-value is usually the identifier of a memory location, an r-value is the value of an expression

  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 is not given a value when upon creation. if this is done accidentally it can cause a program to crash or give sporadic results.

  1. What is undefined behavior?

Undefined behaviour is the result of executing code whose behaviour is not well defined by the C++ language

1 Like
  1. A named object
  2. A declaration statement of an object
    3, It’s when variable is assigned a memory address in RAM
  3. Different data types tells how the complier should store them
  4. Not much
  5. May, may not work, might create a lot of compiler bugs
1 Like
  1. A variable in C++ is a named object.
  2. The definition of a variable is using a special kind of declaration statement.
  3. Instantiation of a variable is to be created and assigned a memory address.
  4. An l-value represents an object that occupies some identifiable location in memory. R-value is an expression that does not represent an object occupying some identifiable location in memory.
  5. An uninitialized variable is a variable that has not been given a known value. If this happens, it may create some issues.
  6. Undefined behavior is the result of executing code whose behavior is not well defined by the C++ language.
1 Like

The l and r value is not a type, but refers to the left and right side of the assignment operator. :slight_smile:

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

  2. What is the Definition of a variable?
    A declaration for a variable.

  3. What is Instantiation of a variable?
    The object assigned a memory address

  4. What is the difference between an l-value and an r-value?
    The article given had nothing on the last 3 questions. I don’t know how people are getting the answers?

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

  6. What is undefined behavior?

1 Like

I’m not sure either, I didn’t read the article :sweat_smile: if I redo the course some day I’ll make sure to include it.

Anyway, the r and l value refer to the right and left part of the assignment int x = 5 here x is the l value and 5 is the r value.

An uninitialized value is a value that hasn’t been given a value yet and might cause undefined behavior which is not well defined in the language. :slight_smile:

1 Like
  1. a named object is called variable

    1. a special kind of declaration for a variable, for example int x; so we have a variable x that can hold an integer value
  2. Instantiation is a fancy word that means the object will be created and assigned a memory address

  3. An l-value has a persistent address. An r-value hasn’t a persistent address.

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

  5. It is the result of executing code whose behavior is not defined by the language. One example is using a uninitialized variable.

1 Like
  1. A variable is a named region of memory.
  2. A variable has an identifier, a type, and a value.
  3. Instantiation means the object will be created and assigned a memory address. Variables must be instantiated before they can be used to store values.
  4. An I-value is an object reference and an r-value is a 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. An uninitialized variable is a variable that has not been given a value by the program.
  6. Using the value stored in an uninitialized variable will result in undefined behavior.
1 Like
  1. What is a variable in C++?
  • A variable is a named memory location.
  1. What is the Definition of a variable?
  • The definition of the variable determines how the compiler will interpret the data stored in memory. Is it an integer or a double precision variable, etc.
  1. What is Instantiation of a variable?
  • Instantiation is the process of loading the variable into memory so it can be used by the program.
  1. What is the difference between an l-value and an r-value?
  • lvalue is an object reference and an rvalue is a value
  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 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?
  • Undefined behavior means the compiler (implementing C/C++ standard) is free to do anything as these are undefined by the C++ standards. So if I create a variable but fail to assign a value to it, it is undefined. If I try to use this variable in some operation, the results are unpredictable.
1 Like
  1. What is a variable in C++? It is an object with a name.
  2. What is Definition of a variable? It is a storage with name that holds data value.
  3. What is Instantiation of a variable? A piece of RAM memory is set aside for the variable.
  4. What is the difference between an l-value and an r-value? I-value refers to memory location which identifies an object, r-value is an expression that 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? A variable that has not been given a known value and has a random unexpected result.
  6. What is undefined behaviour? Is the result of executing code whose behavior is not well defined by the C++ language.
1 Like
  1. What is a variable in C++?

A variable is named object.

  1. What is the Definition of a variable?

A variable is an object type coupled with a name. It references a location in memory.

  1. What is Instantiation of a variable?

Instantiation of a variable is the assignment of the variable to a location in memory.

  1. What is the difference between an l-value and an r-value?
    The I value refers to the left side of the assignment operator whereas the r value refers to the right side. The main difference is whether the data occupies some identifiable location in memory.

  2. 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 known value. If this happens, it may cause unexpected behavior or even cause the program to crash.

  1. What is undefined behavior?

Undefined behavior occurred when a program operates in a way that is not intended by the source code.

1 Like