Variables in C++ - Reading Assignment

  1. What is a variable in C++?

Valuable is a type of data have been used in proccess.

  1. What is Definition of a variable?

Value being stored in ram to make operations with variable.

  1. What is Instantiation of a variable?

The storage of variable inside ram with a location.

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

L value is the one stored in ram and also used as an output value. R Value is the value itself that not stored in ram.
5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?

When there’s no value defined, variable is uninitialized. In that case, each time computer takes a random number.

  1. What is undefined behaviour?

Undefined variable results undefined behaviour

1 Like
  1. What is a variable in C++?
    Ans: A variable in C++ is simply an object that has a name.

  2. What is Definition of a variable?
    Ans: A variable is a placeholder in computer memory to hold some value.

  3. What is Instantiation of a variable?
    Ans: Instantiation literally means “example of something”. So instantiation of variables means declaring a variable e.g. to instantiate an integer x we will say int x;

  4. What is the difference between an l-value and an r-value?
    Ans: An l-value is a value with persistent memory address and r-value is something without proper persistent memory address. e.g. most integers are r-values and most variables are l-values.

  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    Ans: Uninitialized variable is a variable without any proper value assigned to it hence C++ compiler will assign any memory to it whatever it can find suitable (randomly) like garbage value. It can lead to many unexpected results.

  6. What is undefined behaviour?
    Ans: Below can be some examples of “undefined behavior”.

  • Your program produces an incorrect result consistently.
  • Your program produces different results every time it is executed.
  • Your program behaves inconsistently (sometimes produces the correct result, sometimes not).
  • Your program seems like its working but produces incorrect results later in the program.
  • Your program crashes, either immediately or later.
  • Your program works on some compilers but not others.
  • Your program works until you change some other seemingly unrelated code.
1 Like

Hello @ivan and dear community,

  1. What is a variable in C++?

A variable is a piece of memory from the RAM which can store values.

  1. What is Definition of a variable?

int iVariable;

  1. What is Instantiation of a variable?

int iVariable = 10;

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

l-value:
int x = 10;
x is a l-value.

r-value:
int x = 10;
10 is a r-value.

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

It’s a variable that was only declared, not initiated.
The output-result is related to the compilers behaviour. May it works, may it works not.

  1. What is undefined behaviour?

Different results, different runtimes (crashes, …), Code works on some compilers and at some not, …

Kind regards
Kevin

1.An object that has a name is called a variable.
2. Definition of a variable specifies the name and type of the variable.
3. Instantiation means giving a value to the variable.
4. l-values have a permanent address while r-values do not have permanent addresses.
5.An uninitialized variable grabs whatever garbage value is already there in memory location.
6. Undefined behaviour means unexpected behaviour. The result may or may not be as expected.

  1. What is a variable in C++?
    Objects declared to be used at any moment on the program.
  2. What is Definition of a variable?
    Declare the type of variable we want to use, could be defined has “int, string, float”, etc…
  3. What is Instantiation of a variable?
    Memory allocation of the variable (RAM).
  4. What is the difference between an l-value and an r-value?
    l-value have persistent memory allocation, r-value does not have persistent memory allocation.
  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    Uninitialized variable: a variable without a value on it. (try to avoid them)
    Behaviour will be different depending on the compiler, some will just run the variable and allocate them on memory, leading to undefined issues in the future; Others will not run the program, showing a undefined error.
    Best practice is just to avoid create uninitialized variables.
  6. What is undefined behaviour?
    The result by executing code not well defined in the programming language. Example: forgot to close an statement with the wellknow “;”.
  1. What is a variable in C++? It’s an object that has a name
  2. What is Definition of a variable? It’s the use of a declaration statement called definition, to create a variable.
  3. What is Instantiation of a variable? It is setting a side a piece of memory from RAM for a variable.
  4. What is the difference between an l-value and an r-value? An l-value has a persistent address in memory, and is the only value that can be on the left side of an assignment statement. On the other hand, r-value is not associated with a persistent memory address, I.e. single numbers.
  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable? An uninitialized variable is such that is not given an initial value. In such case, using values of uninitialized variables can lead to unexpected results, as the computer will assign some unused memory to it.
  6. What is undefined behaviour? It is a not well defined behavior of a code that leads to unpredictable result after execution.
  1. What is a variable in C++?
    An object with a name.
  2. What is Definition of a variable?
    Variable is a portion of memory that has a name and the variable stored in memory.
  3. What is Instantiation of a variable?
    Instantiation is when a code is being excited and a piece of memory is being reserve for it.
  4. What is the difference between an l-value and an r-value?
    I-value last throughout the code till is being change or the program is being restarted. Whereas for r-value it only last within the statement, upon completing the statement the memory would be released.
  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
    A variable that doesn’t have a value being set. We can expect the variable to return a results of not intended values.
  6. What is undefined behaviour?
    The value of unintialized variable
  1. What is a variable in C++?
    A named object

  2. What is Definition of a variable?
    A piece of memory that has a name and is currently defined.

  3. What is Instantiation of a variable?
    Instantiation is creating an object and assigned a memory address.

  4. What is the difference between an l-value and an r-value?
    l-value is the left side of an assignment and r-value is the left. l-value point to the memory address which will be careful of storing the value given in r-value

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

  • Uninitialized variables may produce problems if the garbage that exists in the allocated variable space gets used as valid data.
  1. What is undefined behaviour?
    Using the value from an uninitialized variable
  1. It is an object that is kept in the computer’s memory and that can be accessed to be used in our program.

  2. A variable is a named object.

  3. A variable is instantiated at compiling time. It is necessary to do so in order for the variable to be used in our program. It is only then that the variable is assigned a spot in the memory and can be called upon.

  4. I have honestly did not encounter anything about these terms while reading. I’ll look through others’ answers to shed some light on this.

  5. An uninitialized variable has not been assigned any value. It will be stored randomly into the memory and take on whatever value has been residing in that memory spot. Basically, it may return any value.

  6. It is executing a piece of code whose behaviour has not been defined by the language.

  1. In C++ a named object is called a variable.
  2. A variable is a named region of memory.
  3. Installation of a variable means that the object will be created and assigned a memory address.
  4. r-value is a variable without an address, whereas I-value is a varible that have a persistent address in memory.
  5. An uninitialized variable is in memory, but she doesn’t have value assigned to it. Using such a variable can cause unexpected behavior.
  6. It means that anything can happen during the program execution, as C++ does not have rules to do what is supposed to happen.
1. What is a variable in C++?

It’s a named object, in other words a named region of memory. The name of the object is called an identifier.

2. What is Definition of a variable?

The definition of a variable is its declaration statement.

3. What is Instantiation of a variable?

It is the assignment of an address in the memory for that variable.

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

The most common place to run into these terms are in compiler error & warning messages. Lvalue, locator value, is a value that has an address in memory, it’s a named object or variable. Rvalue is an object that doesn’t have an identifiable location in memory. They are used to perform a computation and then are discarded.

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, usually through initialization or assignment. C++ does not initialize most variables to a given value automatically, therefore the variable is assigned whatever value the address in memory has at that point in time. The behaviour of those will be erratic because we cannot know what value will be used.

6. What is undefined behavior?

The result of executing code whose behavior is not well defined by the C++ language. The result can be almost anything, including something that behaves correctly.

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

What is Definition of a variable?
a memory location for holding a value for an object

What is Instantiation of a variable?
Instantiation is a fancy word that means the object will be created and assigned a memory address.

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

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
An uninitialised variable is a variable that has not been given a known value. If it is used,
it will produce whatever value is present at its memory location causing unpredictable behaviour.

What is undefined behaviour?
Random behavior is when the program doesn’t run as you expect everytime

  1. A Variable is a named object or named storage/data
  2. Defines the type of data and the location of the data of the respective Variable
  3. Instantiation is when the object is created, the Variable can only run (runtime) when instantiation happens
  4. I-value allows an object to be changed and has a memory location, r-values do not represent an object, therefore do not have a memory location
  5. Variable is in memory but no value has been given, result; unexpected behaviour, e.g. program crashes, error alerts etc
  6. Undefined behaviour is when the program shows unexpected results
  1. What is a variable in C++? variables are a named region of storage that can store a data value.
  2. What is Definition of a variable? A variable is an object with a type assigned to it that is identified with an identifier. I.e. int x; is the identification of an integer variable identified as ‘x.’
  3. What is Instantiation of a variable? variables are a named region of storage that can store a data value. This assignment of the identifier to the variable and its type is made at runtime and the process of doing so is called instantiation.
  4. What is the difference between an l-value and an r-value? the l value is the variable on the left side of the assignment, and the r-value is the data value on the right side of the ‘=’ assignment operator.
  5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable? An unitialized variable is one that has not been given a type and an identifier. The compliler may or may not complain about it, however, it is a great way to have your program intermittently crash.
  6. What is undefined behaviour? Undefined behavior is the situation whereby there is no real way to tell how an object will behave. There is not too much error checking in C++, so if you overwrite an array, C++ may not complain, and then you may have stomped on an error of memory that may be critical to your computer’s functioning properly.

1. What is a variable in C++?
A named object.
2. What is Definition of a variable?
A variable is a named region of memory.
3. What is Instantiation of a variable?
Initializing or declaring a variable which can be used later.
4. What is the difference between an l-value and an r-value?
An I-value has a persistent address in memory. An r-value does not have a persistent address in memory.
5. What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
It is a variable which has not been given a value. It may may hold unknown information in it’s memory value from previous programs which can cause unexpected behavior.
6. What is undefined behaviour?
Execution of code whose behavior is not well defined by the language.

1 - A variable in C++ is a named object.
2 - Definition is a special kind of declaration statement used to create a variable of a given type.
3 - Instantiation is a word that means the object will be created and assigned a memory address.
4 - L-value refers to memory location which identifies an object. R-value refers to data value that is stored at some address in memory.
5 - An uninitialized variable is a variable that doesn’t have a defined value, so it will be associated with whatever value located in the memory location it resides.
6 - Undefined behavior is the result of executing code not well defined in C++.

  1. A named region of memory
  2. It’s the process that consist to allocated space in memory
  3. It’s an example of value that the variable can take we can call it an assignment
  4. Who knows?
  5. A variable without instantiation is dangerous because we can’t know what does it store
  6. Undefined behavior is when a variable is uninitialized so you cannot predict what the variable will do
  1. a named object
  2. a memory location for holding a value for an object
  3. assigning a value on creation
  4. l-value is the assignee, r-value is an expression that determines the value to assign
  5. declared but not instantiated, behavior is unpredictable
  6. may work, may not , could be consistently wrong result, could be inconsistent, may appear to work but cause downstream bugs

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. The name of the object is called an identifier ( therefore an identified object is variable). or , variable is a named region of a memory
2. What is Definition of a variable?
Special kind of declaration in the creation stage, used in order to define the variable by name and type.
3. What is Instantiation of a variable?
Assigned a memory address (in order to be able to assign to the defined variable values).

4. What is the difference between an l-value and an r-value?
I -value is an expression with a memory address (can be placed on the left side of the assignment operator), r- value is defined as “all other expressions”. l-values have a persistent address in memory. r-values are not associated with a persistent memory address and are discarded at the end of the statement in which they occur.
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 (usually through initialization or assignment) is called an uninitialized variable.You can expect from such a variable to have undefined behaviour.
6. What is undefined behaviour?
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.

  1. What is a variable in C++?
    A variable is a named object / a named region of memory storage.
  2. What is the definition of a variable?
    A variable is an element, feature, or factor that is liable to change or vary.
  3. What is instantiation of a variable?
    Instantiation means that 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?
    l (ell) value (locator value) is a function or object that has an assigned memory address. When l values were originally defined, they were values that were suitable to be on the left hand side of an assignment expression. Later this changed.
    r value are said to be “everything that is not an l value” (Chap 15.2). They can be literals, temporary values, anonymous objects that do not have an address.
  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 (usually through initialization or assignment) is called an uninitialized variable. This may result in undefined behavior.
  6. What is undefined behavior?
    Intermittent crashes possible and sporadic results.