Variables in C++ - Reading Assignment

  1. A named object is called a variable.

  2. Is a region of storage (usually memory) that has a value and other associated properties.

  3. Instantiation means the object will be created and assigned a memory address.

  4. Am 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. Put simply, l-value is an object reference and an r-value is a value.

  5. An unitialized variable is a variable that has not been given a value by the program. Using the value stored in an unitialized variable will result in undefined behavior.

  6. It renders the entire program meaningless if certain rules of the language are violated.

1 Like
  1. A variable is a named object
  2. The definition of a variable is a declaration of its value
  3. Instantiation of a variable is when an object is created and assigned a memory address
  4. An I value is a static value, and an rvalue is the result of an expression
  5. An uninitialized variable doesn’t have a known value
  6. Undefined behaviors is executing code, not in the scope of C++, mainly caused by a mess up like having an uninitialized variable.
2 Likes
  • What is a variable in C++?
    A variable is a named object, a named region of space in memory.

  • What is the Definition of a variable?
    A definition is some statement that defines a variable.

  • What is Instantiation of a variable?
    An instantiation is when a variable is created in memory and assigned a location.

  • What is the difference between an l-value and an r-value?
    l-values are the objects and can be referenced. r-values are assignments that change the values in objects. Eg: int x = 1; int x; is a l-value, 1 is an r-value.

  • What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    An uninitialized variable will simply point to the memory space assigned and that location will contain whatever was left there (or not) from some other event. Content is unpredictable therefore behavior is unpredictable. .

  • What is undefined behavior?
    Undefined behavior is when a program will run or try to and the results may not be defined. For example, going past the end of an array is permitted but will cause a crash when the program is executed.

1 Like
  1. A variable is a name object. An object is a region of storage where values are stored.

  2. A definition is a declaration statement that defines the variable.

  3. Instantiation is when a object with a name (variable) is created and assigned to a memory address.

  4. I-value is a static value that refers to the memory address whilst r-value doesnt and is the data in the expression of a variable.

  5. An uninitialised object is an object that has not been assigned a value. This will have unintended consequences in the program as any value can be assigned to that object.

  6. Undefined behaviour from a program without clearly defined steps may result in unexplained outcomes such as values or crashing.

1 Like
  1. variable is a named object
  2. variable is a named region of storage that can store a data value
  3. instantiation means that the object has been created and assigned a memory address
  4. l-value is something that points to a specific memory location. r-value is something that does not point anywhere and is temporary and short lived.
  5. declared but not instantiated, behaviour is unpredictable
  6. undefined behaviour has no restrictions on the behaviour of the program and can exhibit unexpected results
1 Like

Variable in C++ - Reading Assignment.

  1. A Variable provides us with a named region of memory storage that our programs can manipulate.

  2. Definition of a variable means that an instruction is written by a programmer telling the compiler to create the storage in a memory location.

  3. Instantiation is when an object will be created and assigned a memory address.

  4. The difference between a l-value and an r-value is that the l-value is on the left-side of the assigned operator and can be modified while the r-value, right-side, is a temporary value that does not persist beyond the expression that uses it.

  5. An uninitialized variable is variable that has not been given a value by the program (generally through initialization or assignment).
    The behaviour you can expect when you use uninitialized variable is that you may have your program intermittently crash and produce sporadic results.

  6. An undefined behaviour is the result of executing a code whose behaviour is not well defined by the C++ language.

2 Likes
  1. What is a variable in C++?
    A variable is a named object which usually lives in memory and has a value and other associated properties.

  2. What is Definition of a variable?
    A definition is a special kind of declaration statement used in order to create a variable.

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

  4. What is the difference between an l-value and an r-value?
    l-value refers to the memory location which identifies an object while an r-value refers to the data which is stored at a memory location.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    An uninitialized variable is a variable which has not been assigned a known value. An uninitialized value may cause a program to behave unexpectedly.

  6. What is undefined behaviour?
    Undefined behaviour is the result of executing code whose behaviour is not well defined by the C++ language resulting in unpredictable results and/or crashes.

2 Likes

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

2. What is the Definition of a variable?
this one has more defenitions a variable in c++ can be an object, a data structure in memory and a function.

3. What is Instantiation of a variable?
this is where the data of a specific int or other data type is stored in the computer and how the computer can find it back when the data type gets called.

4. What is the difference between an l-value and an r-value?
it has the same type of data but the names are different and stored in different places in the memory of the computer.

5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
if u use an uninitialized variable you can create a lot of bugs because the stage of that variable is undefined so there’s no data to compile or to work with.

6. What is undefined behavior?
undefined behavior is something bad you don’t want as a programmer because the program doesn’t recognizes the code that’s in that program. because there is no essential data to work with for the program.

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

  2. What is the Definition of a variable?
    = A declaration statement used to to create a variable.

  3. What is Instantiation of a variable?
    = It is when a variable is created and assigned a memory address.

  4. What is the difference between an l-value and an r-value?
    = An l-value is an expression that refer to a memory location, it may appear on both sides of the left-hand or right-hand of an assignment.
    An r-value refers to data that is stored at a memory location, it can not have a value assigned to it, therefore it can only appear on the right-hand side of an assignment.

  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 assigned a value. When you use a uninitialized variable the computer will assign some unused memory to it, this can result in all sorts of results.

  6. What is undefined behavior?
    = Undefined behaviour is the result of executing code that are not well defined by C++, like using a uninitialized variable for an example. It can end in unexpected results like inconsistent behaviour.

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

  2. What is the Definition of a variable?
    It’s a special kind of declaration statement used in order to create a variable.

  3. What is Instantiation of a variable?
    Instantiation is a fancy word that means 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 is an expression that yields an object reference, such as a variable name, an array subscript reference. It has always a defined region of storage, so you can take its address.
    An r-value is an expression that does not necessarily have any storage associated with it.

  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 given a value by the program.
    From this variable you can expect undefined behavior.

  6. What is undefined behavior?
    There are no restrictions on the behavior of the program.

2 Likes
  1. A variable is a named object. The ā€œname of the objectā€ is called an identifier.

  2. The definition of a variable is is defined by its variable type (ie int, which means the type of value the variable is).

  3. Instantiation of a variable means when ā€œruntimeā€ occurs, the variable becomes instantiated. The object is created and assigned a memory location and whenever this variable is read, it accesses the value of this variable at the specified memory location.

  4. An l-value has a persistent address and r-values do not contain a persistent address and are discarded at the end of the statement.

  5. An uninitialized variable is a common mistake made my the programmer who forgets to add or define the value of an object. The variable is, however, in memory/previously used in some other code - so the compiler will draw upon that value and use it here -> which leads to unexpected values and behaviors until the editor can find the issue in the code.

  6. Undefined behavior is when the code will just not run because a variable isn’t properly defined in the correct location, or it’s just not well defined/properly placed in the code.

2 Likes
  1. A named object.
  2. A variable is a named region of memory.
  3. Instantiation is creating an object and assigning a memory address.
  4. An I-value has a persistent address and an r-value does not have a persistent address.
  5. An uninitialized variable has been named in memory but has not been assigned any value. This can result in undefined behavior.
  6. Undefined behavior is the result of using uninitialized variables.
1 Like
  1. A variable in C++ is a named region of memory.

  2. Definition of a variable refers to the act of using a declaration statement to create a variable.

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

  4. I-values have a fixed location in memory, whereas an R-value is discarded after the expression has been evaluated.

  5. An uninitialized variable is one that has not yet been assigned a value. If accessed during runtime, an uninitialized variable can cause erratic behavior.

  6. Undefined behavior is the result of executing code that is not well defined by the language ie. calling an uninitialized variable.

1 Like

Undefined behavior is actually any behavior that is not defined in the language specification. The code will run but its behavior is unpredictable and can be different when using different compilers or architectures. :slight_smile:

  1. What is a variable in C++?

A named object is a variable

  1. What is Definition of a variable?

An object is a region of storage (usually memory) that has a value and other associated properties (that we’ll cover in future lessons).

  1. What is Instantiation of a variable?

Instantiation means the object will be created and assigned a memory address

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

I value is the assignee, r value assigns the value to assign

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

An uninitialized variable has an undefined value, often corresponding to the data that was already in the particular memory location that the variable is using.

What is undefined behaviour?

This can lead to errors that are very hard to detect since the variable’s value is effectively random, different values cause different errors or none at all.

1 Like
  1. Data is any information that can be moved, processed, or stored by a computer. It is symbols that can be interpreted.

  2. A value is a single piece of data stored in the computer’s memory.

  3. A variable is a named object, which is a region of storage/memory that has a value.

  4. An identifier is the name of the object/variable. Used to guide the program in accessing specific data/variables.

  5. A type defines for the compiler what type of value will be stored by the variable. And by extension instruct the program how to interpret the variable.

  6. An integer is a type of data that represents a whole number (no fractional representation; ie. 2, 5, -3, -22, etc.)

  1. What is a variable in C++?
    A variable in C++ is an object which has been bound to an identifier.

  2. What is the Definition of a variable?
    A variable needs to be defined before it can be used in a program. A variable is defined by a special declaration statement in a C++ program. For example, a ā€œint x;ā€ statement will declare an integer variable.

  3. What is Instantiation of a variable?
    A variable is instatiated at runtime when a specific region of memory is assigned to store the value and properties of the variable and bound to the variable’s identifier.

  4. What is the difference between an l-value and an r-value?
    An l-value is an object reference (e.g., variable name), and a r-value is a value (e.g., an integer, a string, etc.).

  5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    An uninitialized variable is an variable whose value is not specified upon its declaration. Depending on the compiler used, uninitalized variables would either trigger compiler errors or it would result in unpredictable values being used as the variables’ values.

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

1 Like

Where did you get the questions from? The questions in this course are different than the ones you answered.

hahah, that’s too funny!!! :laughing: did I miss understand the assignment?
when I read the assignment it stated:"

At the bottom of the article you’ll see a quiz - make sure to do the quiz!

Post your answers and feel free to discuss the quiz in this thread"

I interpreted that to mean post my answers to the quiz in the forum!

the questions actually shown on the assignment page state the following in terms of instructions: "

Think about the following questions while reading:"

I complied with the instructions as written on the Academy page.
Would you like me to also answer the ā€œkeep in mind/ thinkingā€ questions here?!? :thinking:

Ohh, you can solve the quiz on the website :slight_smile: the topic has its own questions on the top of the thread.

1 Like