Variables in C++ - Reading Assignment

  • What is a variable in C++? Named object

  • What is the Definition of a variable? A specific type/name for a variable.

  • What is Instantiation of a variable? A chunk of memory set to utilize the RAM of a CPU for a variable.

  • What is the difference between an l-value and an r-value? l-value has-persistent defined memory in the address & r-value is not associated with a persistent memory address.

  • What is an uninitialized variable and what kind of behavior can you expect from such a variable? A uninitialized variable can create unexpected results it will not initialize correctly without being assigned a value.

  • What is undefined behavior? The resulting value of an uninitialized variable, executing code whose behavior is not well defined by the language, because of this it would create a bug in the code causing strange behaviors in the program, such as the program will crash or not launch at all, if it dose launched it will experiance inconsistent behavior.

2 Likes

Hello guys I am so happy to be here. Finally some new things for me to learn C: !

1.A variable is an named object in c++.

2.A region of storage where you can save data for future use.

3.Instantiation is what happens when you start a program and the computer assigns a memory place for the variable so it can use itfrom that point forward.

4.L value is an identifier of an object and R value is the data of that object which will be stored in the memory( int i = 5; where I will be an lvalue and 5 an rvalue).

From google: An lvalue refers to an object that persists beyond a single expression. An rvalue is a temporary value that does not persist beyond the expression that uses it.(https://press.rebus.community/programmingfundamentals/chapter/lvalue-and-rvalue/#footnote-148-1)

5.An unitialized variable is a variable without a defined value. C++ doesnt give variables an automatic value of 0 so if you try to access an unitialized variable you will get a random value.

6.undefined behavior is trying to execute code which is outsie the rules of the language that you are using. your program will go crazy :))

2 Likes

Ans 1:
A variable in C++ is a computer language tool to access computer memory, using an object of data, a reference point, a place where value(s) is compiled by the computer’ processor. Variables also have specific identifiers attached to them of type and value. It’s this type/value that C++ interprets when compiling to memory and retrieving from memory. Finally, it is a named region where a specific value can be stored and thus recalled.

Ans 2:
The definition of a variable is a named region where data is stored in a computer’s memory.

Ans 3:
Instantiation of a variable is when an object is created and assigned a specified space in memory. (loosely…an address, a home etc.)

Ans 4:
An I-value is often an identifier of a location of an object stored in memory. An R-value on the other hand is a value that is stored at some address in the memory of the computer. R-value is an expressional value which value can only be derived from the RHS of an assignment operator. (eg. ā€˜=’)

Ans 5:
An uninitialized variable in C++ is when a variable is not given a value or an assignment by the program. Undefined behaviour is characterised by an uninitialized variable. This value type of variable becomes stored uninitialized.

Ans 6:
Undefined behaviour (UB) is when the computer language code to be executed is deemed to be unpredictable. This language does not hold to the established conventions as it was an uninitialized value type stored variable by the program.

2 Likes
  1. What is a variable in C++? A named object, an object being a region of memory. Therefore a variable is a memory location which can be referenced via it’s name rather than having to know it’s actual address in memory.

  2. What is the Definition of a variable? It is a declaration statement with syntax ā€œType Identifierā€ which creates a memory location, referenced by name ā€œIdentifierā€, and that the value stored in that location is to be interpreted as data type ā€œTypeā€.

  3. What is Instantiation of a variable? This is the creation of an object and assignment of its memory location during runtime.

  4. What is the difference between an l-value and an r-value? An l-value is a value that has a memory address. An r-value is an expression which evaluates to a value and does not qualify as an l-value.

  5. What is an uninitialized variable and what kind of behavior can you expect from such a variable? An uninitialized variable is one which has not yet had a value assigned to it. Since most variables are not assigned a given value prior to initialization, an uninitialized variable could cause undefined behavior.

  6. What is undefined behavior. This is behavior which is unpredictable and could produce erroneous results.

1 Like
  1. a variable is an object that has a named identifier.
  2. A Definition specifies the variable type and name.
  3. Instantiation assigns a specific memory location for a variable, so when the compiler sees that variable later it knows to look in that memory location for its value.
  4. I-value are values that are stored in a specific memory location. r-values do not have a specific location in memory.
  5. an uninitialized variable is an object that has not been given an assigned value. So the value of this variable will be whatever data happens to be stored in the same memory location as the variable at the time.
  6. Undefined behavior is when executing a program could produce different and unpredictable results every time you run it.
1 Like

1.) A Variable in C++ is a named object.

2.) A Definition of a variable is a special declaration statement stored in memory.

3.) Instantiation aka ā€œInstanceā€ of a variable means the object will be created and assigned a memory address.

4.) An I-value refers to a location in it’s memory and an r-value refer to values without a location within the memory.

5.) An uninitialized variable is a non-assigned value, "No value in memory and can cause problems when running the code.

6.) Undefined behavior is behavior that can change when you execute the code and can actually change each time you execute the code.

2 Likes
  • What is a variable in C++? It is a named region of memory.
  • What is the Definition of a variable? A definition is a declaration statement used to create a variable.
  • What is Instantiation of a variable? It means the object is created and assigned a memory address.
  • What is the difference between an l-value and an r-value? An lvalue is an object reference and an rvalue is a value.
  • 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 an rvalue yet. Accessing that variable can give unexpected results because it will just return whatever data was in that memory location.
  • What is undefined behavior? 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 an object that has an identifier. This is contrary to JS where a variable is considered the ā€œidentifierā€ of whatever you name with a variable.

  2. A variable definition is a declaration statement that lets the compiler know you are declaring a variable with a name. This definition will also tell the compiler what type of variable this is.

  3. Variable Instantiation occurs when an object is created and given a memory address.

  4. An l-value refers to memory location that identifies an object. These are normally on the left side of an assignment operator (=) but can be in certain situations. An r-value is a value that refers to data that is stored at an address in memory. An r-value is normally on the right side of an assignment operator.

  5. An uninitialized variable is a variable (object) that has been declared but has not been assigned a value. An uninitialized variable will show up as ā€˜undefined’ in the console.

  6. An undefined behavior is the result of a program whos behavior is unpredictable.

1 Like

r-values don’t have a location in memory. :slight_smile:

1 Like

Oh shoot ok. So the l-value is stored in memory and the l-value is referenced to figure out what the data inside of it is which would be the r-value?

L and R value basically just refer to left or right side of the assignment operator (=). Personally I don’t use these terms and haven’t really heard of them before taking over this course tbh :stuck_out_tongue: its not something you will hear every day so don’t bother to much if you don’t know.
Basically what it means is if when you have an assignment like x = 1 + 2 means that x is the variable stored in memory (l value) and 1 + 2 is the temporary value (r value). :slight_smile:

3 Likes

Ahh ok I see what you mean. Thank you for that clarification on this!! Trying to wrap my head around the meaning of those were kind of driving me crazy so that straightforward explanation really helped. :+1:

Hello,

  • What is a variable in C++?
    A named object which gives access to a specific location in memory where a value can be stored and retrieved from.

  • What is the Definition of a variable?
    Definition of variable means giving a name and a type to a variable (for instance, the statement ā€œint a;ā€ defines the integer variable named ā€œaā€).

  • What is Instantiation of a variable?
    The creation of the variable, i.e. its memory space allocation.

  • What is the difference between an l-value and an r-value?
    I did not see these notions in the article… But by reading the other answers, I understand that l-value is what we find on the left end side of an assignment expression and so is stored in memory. While r-value is what we find on the right side of an assignment and is therefore temporary (not stored in memory).

  • What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    Unassigned variables are variables which are instantiated, but with no initial value yet, meaning that their allocated memory space could contain whatever value was left at that memory location. Therefore, unassigned variables are not reliable.

  • What is undefined behavior?
    Undefined behavior is the result of executing code which is unpredictable, because, for instance, using an unassigned variable.

Fabien

2 Likes

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

2. What is Definition of a variable?
Specifying a type and a name for a variable for example

3. What is Instantiation of a variable?
Allocation of memory in RAM for a variable

4. What is the difference between an l-value and an r-value?
An l-value has a persistent address. An r-value hasn’t a persistent address.

5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
An uninitialized variable is in memory, but she doesn’t have value assigned to it. Using such a variable can cause unexpected behavior.

6. What is undefined behaviour?
Undefined behavior is when the result of the program may exhibit unexpected results. He can work well the three first executions and not at the fourth for example.

2 Likes

A variable is a named specific region of memory in a computer where a value can be stored

The definition of a variable is the assignment of a data type and a name that a variable can hold: for example int x;

Instantiation of a variable is the assignment of a value to a defined variable at the time the variable is created

The l value is the variable name and the r value of a variable is the data held in memory referred to by the l value. The data can be in the form of a discrete value, an expression, function or object.

An unitialized variable is one that has been defined but not assigned a value, and since C++ does not automatically initialize undeclared variables to say 0 - it can introduce bugs to a program as the uninitialized variable takes on the value of any data that happened to previously be at that memory location, usually considered garbage.

Undefined behaviour is when the output is not consistent with the behaviour and results you would expect as the output of a program

1 Like
  1. A variable is a named object
  2. A declaration statement in which the variable is instantiated
  3. Assigning a memory address to the created variable object (i.e. the variable name is associated with a region of storage)
  4. An l-value points to a specific memory location, existing as a variable and r-values don’t point anywhere, they are temporary and shortlived only holding memory in a temporary register for the duration of the program.
  5. A variable that has not been given a known value at assignment/instantitation in the program. Undefined behaviour will arise as the value of an uninitialized variable will simply be made up of whatever value happens to have been left in that memory location prior to assignment.
  6. The result of executing code whose behaviour is not well defined by the C++ language.
1 Like
  1. A variable is a named object, a container for data that is stored in the memory. In C++ variables do not include functions.
  2. It’s the statement we use to declare the variable.
  3. A variable is instantiated when the program is run, reads the definition, and creates the variable, and stores it in memory.
  4. l-values (left side) are associated with a presistent memory address, while r-values (right side) are not and are discarded at the end of the statement.
  5. It’s a variable that hasn’t been given a value yet. Using one such variable can lead to unexpected or inconsistent results.
  6. Unpredictable behavior caused by using uninitialized variables.
1 Like
  1. What is a variable in C++? A variable in C++ is a named object which is a place to store data in memory. In C++, variables do not include functions.
    2.What is a definition of a variable? It is a value stored in memory. It is a statement used to declare the variable.
  2. What is instantiation of a variable? It is when a variable is called into a program at runtime. A program reads the definition of the variable and creates it and stores it in memory.
  3. What is the difference between an I-value and an r-value? An I-value is the variable on the left of the = sign in an expression. The r-value is to the right of the = sign in an expression.
  4. What is an uninitialized variable and what kind of behavior can you expect from such a variable? In C++ an unitialized variable has whatever value is already in memory which could be garbage. Using this kind of variable can result in unexpected or inconsistent results.
  5. What is undefined behavior? It is allowing the compiler to do anything it chooses, even to generate useless data.
2 Likes
  1. A named region of memory
  2. A piece of code identifying the type and name of a variable.
  3. During runtime, the variable will be instantiated by the compiler in a manner appropriate to the definition. This is also when the variable will be assigned a memory address.
  4. l-value refers to a memory address. The definition of r-value does not specify an actual memory address and thus can refer to a variable used in an operation or refer to raw data such as both x and 2 in ā€œx = x + 2ā€.
  5. A variable that has been declared but which has not been assigned a value yet. C++ will not assign a default value to such variables and the compiler will throw an error if the variable is used without first explicitly assigning a value to it (i.e. initializing it).
  6. Undefined behaviour is when the program is not behaving according to the C++ standards.
1 Like

VARIABLES IN C++

  1. A variable in C++ is a named region of memory.

  2. A variable is a special kind of declatation statement.
    Here’s an example of defining a variable named x:
    int x; // define a variable named x, of type int

  3. 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. The difference between an l-value and an r-value
    L-value: ā€œl-valueā€ refers to memory location which identifies an object. l-value may appear as either left hand or right hand side of an assignment operator(=). l-value often represents as identifier.
    R-value: r-valueā€ refers to data value that is stored at some address in memory. A r-value is an expression that can’t have a value assigned to it which means r-value can appear on right but not on left hand side of an assignment operator(=).

  5. Uninitialized. The object has not been given a known value yet. 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 language. The result can be almost anything, including something that behaves correctly. :heart_eyes:

2 Likes