Variables in C++ - Reading Assignment

  1. a named object
  2. declaring a statement with the name and type.
  3. when it is given an assigned location the the RAM
    4.i-values are stored in memory, where r-values do not get stored.
    5.an undefined variable that does not have a value initialized to it.
  4. When a variable is not intialized properly and leads to bugs.
1 Like
  1. variables are a named region (object) of storage that can store a data value
  2. A declaration statement that assigns a memory location for a value
  3. Allocation of memory in RAM for a variable
  4. 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
  1. A variable that hasn’t been given a known value, that when used, will produce whatever value is present at its memory location, causing unpredictable behaviour
  2. unexpected outcomes caused by coding no rules for what should happen
1 Like
  1. A named object
    1. a memory location for holding a value for an object
      3.The process of storing a variable binding to your computer’s memory
  2. I values are continuously stored in memory while R values are discarded after they perform the task of assigning value to an I value
    5.An uninitialized variable is a variable stored in memory, however it doesn’t have value assigned. This type can cause unexpected behavior.
  3. A result of executing code whose behavior is not well defined.
1 Like

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

What is the Definition of a variable? // A variable is a named region of memory.

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

What is the difference between an l-value and an r-value? // r-values are unassigned values in memory.

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

What is undefined behavior? // The result of executing code not well defined by the language.

1 Like
  • What is a variable in C++?
    In C++ a named object is call a variable.
  • What is the Definition of a variable?
    A declaration statement used in order to create a variable
  • What is Instantiation of a variable?.
    “Instantiation” is when a new instance of the class is created (variable).
  • What is the difference between an l-value and an r-value?
    An l-value is a variable that has a persistent address in memory. It is the value on the left hand side when an assignment is made.
    On the other hand, r-values are not associated with a persistent memory address.
  • What is an uninitialized variable and what kind of behavior can you expect from such a variable?
    Uninitialized variables are variables defined but not initialized whose behavior can be random because they are pointing to a point of memory address used by the system or other program before.
  • What is undefined behavior?
    Random behavior that doesn’t run as you expected
1 Like

1.) A variable in C++ is similar to an object in general programming terms except that in C++ variables exclude functions.
2.) The definition of variable is any named or unnamed object.
3.) Instantiation of a variable is when an object is created and assigned a memory address.
4.) L-value or 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. An R-value or "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.)A variable that has not been given a known value through the process of instantiation.
6.)Undefined behavior is the result of executing code that is not well defined in the c++ language. Undefined behavior happens when the value of a variable is not given a known value.

1 Like
  1. A variable is a kind of object in c++ and is used to store values. It is designated a region in memory that has a data type, identifier, and value associated with it. It’s type is assigned at compile time and it’s value instantiated at run time.

  2. Variables are defined before they can be instantiated and given values. In a variable definition, the data type and name are specified.

  3. The instantiation of a variable creates the object and assigns it a memory location so it can store values.

  4. Rvalues are assigned to lvalues in c++. Lvalues point to their location and typically have a longer life span in a program than rvalues because they are reused. Rvalues are typically used then thrown out so they don’t need their own storage.

  5. An uninitialized variable is defined but not assigned an initial value. Rather, it acquires a default value (often something left over from a previous computation) that happens to be residing in the memory location to which it is assigned. Therefore, (unless, the compiler complains, and throws an error) we can expect an uninitialized variable to behave just like an initialized variable – one that has a value assigned to it.

  6. There are many cases in c++ that result in undefined behavior. Using uninitialized variables is one example. Often in such cases code will execute with inconsistent results or will work with some compilers and not others. It’s best practice to try and avoid cases of undefined behavior whenever possible, or should only be done carefully and intentionally if necessary.

1 Like
  1. An object that is not a function and has an identifier.
  2. A named region of storage that has a value and other properties in it (named object).
  3. The actual creation of an object/reservation of space for it in memory.
  4. l-value is an expression that points to value stored in the memory and therefore can be assigned new value, while r-values are calculated on the move (not stored in memory) and therefore can’t be given a value, only assigned to some l-value.
  5. Variable that has been declared but not given “known” value and therefore gets it’s “default” value based on the data which is already present in that memory segment - it can be pretty much anything.
  6. When block of code is written in a way that the same input in the same other conditions leads to different outputs, making the behavior totally unpredictable.
1 Like
  1. A variable in C++ is a named object used to access memory.
  2. A variable is a named region of memory.
  3. It refers to the allocation of a variable to a memory address.
  4. I-value is the object that appears on the left side of an assignment/expression, while an r-value appears on the right.
  5. An uninitialized variable is a variable that is declared but not assigned a value. It will confuse the program, usually resulting in errors and bugs during runtime.
  6. An undefined behavior is an occurrence due to unpredictable results during runtime.
1 Like

What is a variable in C++?
It’s a named object. An object gives indirect access to memory in C++.

What is Definition of a variable?
The program will use particular declaration statement called a definition.
The definition will give the variable a name and a type.
It will be written in the following format:

int x;

where int is the type of the variable and x is the name of the variable
When the compiler converts the source code, where the definition is held, it will understand that when it sees the identifier x, it is referring to this variable.

What is Instantiation of a variable?
At runtime (when the program is run) the variable will be instantiated which means the object will be created and allocated a memory address.
The variable cannot hold values before it is instantiated (becomes an instantiated object, also known as an instance). At this point the instance will work with the value that is held at the allocated memory location.

What is the difference between an l-value and an r-value?
An l-value is a value that has an address (in memory). They are the only values that can be on the left of an assignment statement. When an l-value has a value assigned to it, the current value at that memory address is overwritten.

An r-value is an expression that is not an l-value. Examples of r-values are literals (such as 3, which evaluates to 3) and non-l-value expressions (eg 5 + x).

x = x + 1; // l-value left of =, r-value right of =, x. Right uses the value stored in memory for x, and it will be used in the expression to add 1. Then it overwrites the value in the memory address for x.

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
Uninitialized means the object has not been given a known value either at point of definition or after definition. It means that at runtime, the program will use the value that is already stored in the allocated memory location, leading to unexpected behaviour. It can be difficult to identify this error, so variables should always be initialised.

Behaviours that may be experienced include:

  • Program may work on some compilers, but not others.
  • Program may crash, either immediately or later.
  • Program may consistently produce the same incorrect result.
  • Program may produce different results every time it is run.
  • Program may appear to behave inconsistently, sometimes producing the correct result, sometimes not.
  • Program may seem to be working but then produces incorrect results later in the program.
  • Program may seem to be working until you change some unrelated code.
  • Or, it may work and provide the expected behaviour and results.

What is undefined behaviour?
The result of executing code whose behaviour is not well defined by the C++ language. So, as C++ doesn’t have any rules determining what happens when you use the value of a variable that hasn’t been given a known value (initialised). Consequently, if you use it, undefined behaviour will result.

Quiz time

  1. What is data?
    Data is any information that can be moved, processed, or stored by a computer.

  2. What is a value?
    A single piece of data stored in memory.

  3. What is a variable?
    It is a named object, that has a type and a name. It can have a single value assigned to it.

  4. What is an identifier?
    The name of an object, it is how the variable is accessed.

  5. What is a type?
    It tells the compiler what sort of value the memory will hold.

  6. What is an integer?
    A whole number, one that does not have any factional parts, eg, 1, 56, 2596.

1 Like

What is a variable in C++?

It is a object with a name which comes in different types integer storage numbers, bool which storage (true/false) or double which can storage decimal numbers.

What is Definition of a variable?

A name “x” and a type example “int” and when the developer runs the code a program starts in the and run in compiler the variable become instantiated which means the variable grow to a object and the object will be assigned a memory adress.

What is Instantiation of a variable?

This is the time when the variable grows from to be a variable to be a object and assigned a memory address.

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

I-value represents an object that occupies some identifiable location in memory. R-value is an exclusion of I-value and does not represent an object occupying some identifiable location in memory.

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

It is a variable which doesn’t have a value only a type and name, when you run a uninitialized variable the computer will assign some unused memory to the uninitialized variable and return nothing or something different every time you do a runtime on the code.

What is undefined behaviour?

Your program produces different results every time it is run.

Your program consistently produces the same incorrect result.

Your program behaves inconsistently.

Your program seems working but produces incorrect later in the program.

Your program crashes immediately or later.

Your program works on some compilers but not on others.

Your program works until you change some other seemingly unrelated code.

1 Like
  1. What is a variable in C++?
    -> It is an named object which is a region of storage that has a value and other associated properties.

2.What is the Definition of a variable?
-> It is to set a value to the memory by defining the type and value.
ex int x;

3.What is Instantiation of a variable?
-> It is to store the varible in the memory in order to use it.

4.What is the difference between an l-value and an r-value?
-> i-value is a object that has space or address in the memory and the r-value does not have address.

5.What is an uninitialized variable and what kind of behavior can you expect from such a variable?
->It is a object that does not have a value assigned yet.

6.What is undefined behavior?
->It is a result of executing code whose behavior is not well defined by the C++ language. Since it is not defined everytime it will produce different result or you would not know what will come up.

1 Like
  1. In C++ a variable is a named region of storage (object).
  2. Definition of a variable is a special statement that assigns name and type of the variable to a memory address.
  3. Instantiation of a variable is an act of object creation and giving it a memory address.
  4. An l-value represents an object with identifiable location in memory whereas memory location of r-value is unidentifiable.
  5. We can say that a variable is uninitialized when it has not been given a known value. Such variable will store in it’s memory location a previously assigned value.
  6. Undefined behaviour is an unpredictable, unplanned result of executing code. It can occur for example as a result of using an uninitialized variable.
1 Like
  1. Variable in C++ i a range of RAM volume that is reserved this variable. We use variables to access memory.
  2. A named object is called a variable.
  3. Instantiation of a variable is when the variable is being created and assigned to memory.
  4. 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. Uninitilazied variable is a variable that has been created without values. It contains values that have already been stored in the memory place that is assigned to the new variable.

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

For admin who is reading this, the article provided does not answer all the questions being asked (you must read other articles on the page in order to asnwer questions). Please check if the article is up to date with given requirements and let me know what is needed to read.
Thanks,
Peter

1 Like

TBH I didn’t read the article, but given that most users including you found the answers then I don’t find it an issue. Doing research on your own is actually a big part of programming :slight_smile:

2 Likes

I understand that doing research on my own is big part of programming, but on the other hand in my understanding the lectures must include all literature needed in order to answer the questions, like is usually when you take othe rlectures here. It is not problem for me to search and find the right answer, i just wanted to let you know that there was probably a change on the site that this lecture is reffering to. Im assuming it has been changed because of following things:

  1. The url that is given under the lecture leads to different url. So when using URL under lecture ( http://www.learncpp.com/cpp-tutorial/14-a-first-look-at-functions/) it opens up a different URL (https://www.learncpp.com/cpp-tutorial/introduction-to-functions/)
  2. Not all the answer can be found on the redirected URL.

Im assuming when the lecture was made for sure all answers could be found under original URL.

For example,lets take a look at following questions:
4. What is the difference between an l-value and an r-value? - the answer can be found here (https://www.learncpp.com/cpp-tutorial/15-2-rvalue-references/) in order to find this article you must forward 10 articles from the first one (http://www.learncpp.com/cpp-tutorial/14-a-first-look-at-functions/).
3. What is instantiation of a variable? The answer to this question can in the next article in regards to given article.

Im not clear which articles must i read in order to progress further, so i need help regarding that.
Im also stating this out just to keep the quality of the course to the standards im sure all of you want them to be.

Best,
Peter

1 Like

Hello @peros369, hope you are great.

Now I understand your point on to keep the quality of the course, but you also had find all the answers on the same website that we suggest to. What I mean is that sometimes you should have to research yourself to get a better understanding about a subject, has you said, programming will require that you learn how to DYOR (Do Your Own Research), the fastest you get use to it, the better for you to solve your own coding issues.

We could set all the directly links on the assignment, so people go read them quickly, but the idea is also to made you able to research sometimes by yourself.

Hope you find this useful.
If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

2 Likes
  1. A named object is called a variable, and the name of the object is called an identifier
  2. A variable is a named region of memory.
  3. Instantiation is a fancy word that means the object will be created and assigned a memory address
  4. 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. Uninitialized variable 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.
  6. The result of executing code whose behavior is not well defined by the programming language.
1 Like

Thank you for your reply.

I understand now that the idea behind is to train us to to do research on our own.

Thanks,
Peter

2 Likes

1 variable in C++ is named region in the memory
2 definition of a variable is a declaration statement
3 instantiation is a fancy word that means the object will be created and assigned memory address
4 l-value has a presistent address, but r-value do not have a persistant address
5 an uninitialized variable is a variable that has not given a known value, if used it will produce whatever value is present at its memory location (which is different each time when accessed causing unpredictable behaviour)
6 unpredictable behaviour resulting from the use of uninitialised variables, because C++ has no rules determining what happens

1 Like