Variables in C++ - Reading Assignment

Welcome to the discussion about the reading assignment about Variables in C++.

Leave your answers to the questions below in this thread. If you have any questions or you want to discuss something connected to the assignment feel free to do it in this thread as well, but please keep everything to the topic.

  1. What is a variable in C++?
  2. What is the Definition of a variable?
  3. What is Instantiation of a variable?
  4. What is the difference between an l-value and an r-value?
  5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
  6. What is undefined behavior?
21 Likes
  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
2 Likes

I think a better definition of 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.

[Off topic]

Code Blocks keeps crashing on me. I installed from ubuntu software center, maybe I should remove and try again.

I switched to clion and is working great but I can only use for 30 days without paying. I will probably buy if EOS is the path I want to take moving forward, jetbrains products rock

1 Like
  1. a named object
  2. a special kind of declaration for a variable, for example int x; so we have a variable x that can hold an integer value
  3. the “reservation” of memory in RAM for a variable
  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. a declared variable whose value in the memory address has not yet been initialized. using such variables can lead to undefined behaviour
  6. Undefined behavior is the result of executing code whose behavior is not well defined by the language.

Switched to Netbeans, seems adequate and stable, but creates a lot of clutter(folders) when you create an application, but may be a good free alternative, I noticed in one of the videos, @ivan had to restart Code Blocks. Also the terminal is integrated which to me is a nicer experience

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.

3 Likes

What is a variable in C++?
An object that has a name
What is Definition of a variable?
A declaration statement used in order to create a variable.
What is Instantiation of a variable?
The piece of memory set aside within the RAM that a statement is executed by the CPU.
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 behavior can you expect from such a 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.
What is undefined behavior?
The result of executing code whose behavior is not well defined by the language.

2 Likes
  1. A variable in C++ is an object that has a name
  2. A declaration statement used to create a variable is called a definition
  3. Reserving the needed memory (RAM) needed for a variable is called instantiation
  4. l-values (the only values allowed on the left side of an expression) are values that have a memory address. (variables is an example of l-values)
    r-values (are allowed only on the right side of an expression) are values that are temporary in nature, don’t have a dedicated memory address and are discarded after the expresion is evaluated
  5. A variable that has not been given a value is called uninitialized. The usage of such a variable leads to unpredictable results as it’s value is being taken from the memory location it has been alocated to.
  6. Executing code whoes behavior & result is not well defined os called a Undefined behavior

1. What is a variable in C++?
An object with a name used to store values

2. What is Definition of a variable?
A piece of memory that has a name and is currently defined and may be defined and vary based on another piece of memory.

3. What is Instantiation of a variable?
Defining and initializing a value in the same step.

4. What is the difference between an l-value and an r-value?
An l-value is persistently defined in memory. An r-value is not defined persistently and may be considered the variation of the l-value variable.

5. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
A variable that has no memory location. We can expect anything except what we expected the variable value to be.

6. What is undefined behaviour?
The resulting value of an uninitialized variable.

1 Like

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

2. What is Definition of a variable?
A definition of a variable is special kind of declaration, where the variable is defined as a particular type that can hold a certain kind of value.

3. What is Instantiation of a variable?
Instantiation occurs when a piece of memory is set aside for a variable in RAM.

4. 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. They are generally temporary in nature 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?
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 (which could be different each time it is accessed), causing unpredictable behaviour.

6. What is undefined behaviour?
Unpredictable behaviour resulting from the use of uninitialised variables, because C++ has no rules determining what happens.

1- Variable in C++ is an allocated memory space used to store a value
2- Definition of a variable is the fact to assign a name and type to a memory point address
3- Instantiation of a variable is the fact to assign a value and specific size to a defined 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
5- Uninitialized variables are variables defined but not initialized whose behavior can be random because the are pointing to a point of memory address used before by the system or other program, or may be never used before, that’s random
6- Random behavior is when the program doesn’t run as you expect everytime

1. An object that has a name.

2. A declaration statement used to create a variable.

3. Reservation of memory in the RAM.

4. 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. An uninitialized variable is a variable that has been defined but has not been given a known value (through initialization or assignment). C++ does not initialize most variables to a given value therefore the default value of an uninitialized variable is whatever value happens to already be in the assigned memory location.

6. The result of executing code whose behavior is not well defined by the programming language.

What is a variable in C++?
- An allocated space in memory defined by the variable name.

What is a definition of a variable?
- A placeholder for a store of value (i.e. ‘X’).

What is instantiation of a variable?
- The creation of the spaceholder in memory specifically allocated for the variable.

What is the difference between an l-value and an r-value?
- L-values are left-side variables (memory spaces) which recieve the value computed by the r-values on the right-side (the value stored within the space allocated).

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.

What is undefined behaviour?
- Functionality that doesn’t exist or is not properly used such that the compilers will not understand.

  1. What is a variable in C++?
  2. In C++, a variable is an object that has a name. An object is a piece of memory that is allocated to store values.

  3. What is Definition of a variable?
  4. A variable can be defined in C++ by using a declaration statement. The data type is stated, followed by the variable name.

    data_type variable_name; 
    
  5. What is Instantiation of a variable?
  6. An instantiation is a piece of memory set aside by the RAM. An instantiation is executed by the CPU after defining a variable.

  7. What is the difference between an l-value and an r-value?
  8. An l-value has a persistent address in memory. An r-value does not have a persistent address in memory. For example, the statement

    int x;
    

    vs

    int 5;
    

    The first creates a new persistent address in the memory of type integer named x. The latter does not create a change in persistent memory because the 5 is not an l-value.

  9. What is an uninitialized variable and what kind of behavior can you expect from such a variable?
  10. An uninitialized is a variable that has not ben assigned a memory by the compiler and the default value is whatever garbage happens to be there in that memory location.

  11. What is undefined behavior?
  12. It is the result of executing code whose behavior is not defined by the language. One example is using a uninitialized variable.

2 Likes

I use it with ubuntu 14.04 without problems. Installed from software center as well.

1 Like

What is a variable in C++? is a piece of memory that can be used to store values
What is Definition of a variable? an element that is able to change
What is Instantiation of a variable? Inicialization of the variable, a piece of RAM is assigned memory location
What is the difference between an l-value and an r-value? l-value is a value that has a persistent address in memory. r-value is a value that has not a persistent address in memory
What is an uninitialized variable and what kind of behaviour can you expect from such a variable? variables that have not been given a known value and C/C++ does not initialize most variables to a given value (0)
What is undefined behaviour? Using the value from an uninitialized variable

  1. Variable is a placeholder or memory location that stores value. It is an Object that has a name. It is defined as
    {type} {name} = {value};

  2. Variable is a named storage that holds some value for our program to manipulate. Varible is defined with its type and assined a value using assigment operator (=).

  3. Instantiation: When a variable is defined and assigned a value at same time e.g.
    int x = 5;

  4. l-value is Left expression and an r-value is Right expression of assigment operator in variable instantiation. l-value is used as named reference to memory location and r-value is evaluated for assignment purpose.

  5. Uninitialized variable is a variable which has been defined but not been instantiated. It is unsafe to do this as it can result in undefined and unexpected behaviour of the program.

  6. Undefined behavior is the result of executing code whose behavior is not well defined by the language. C++ language doesn’t have any rules determining what happens if you use value of a variable that has not been given a known value.

1 Like
  1. A variable in C++ is simply an object that has a name.
  2. In order to create a variable, we generally use a special kind of declaration statement called a definition
    3.When this statement is executed by the CPU, a piece of memory from RAM will be set aside (called instantiation)
  3. An l-value is a value that has a persistent address (in memory).An r-value refers to values that are not associated with a persistent memory address.
  4. A variable that has not been given a known value (through initialization or assignment) is called an uninitialized variable.The default value of that variable is whatever (garbage) value happens to already be in that memory location!
  5. Undefined behavior is the result of executing code whose behavior is not well defined by the language.

What is a variable in C++?
A variable is a place holder that is assigned an address and contains a value. Can anyone tell me how this is similar/different to java variables? Are primitives like int and boolean in java different than C++ variables which are more like java’s reference type Strings?

What is Definition of a variable?
A variable is a memory address (I-value) that stores information such as integers.

What is Instantiation of a variable?
Setting aside memory in RAM for a declared variable, declared in C++ by naming its type followed by an identifier

What is the difference between an l-value and an r-value?
I-values contain memory addresses in RAM and are persistent while r-values are temporary values and can only be used to do operations on.

What is an uninitialized variable and what kind of behaviour can you expect from such a variable?
An uninitialized variable has no value attached to it and can do funky stuff. C++ can assign seemingly random values to an uninitialized variable.

What is undefined behaviour?
Behavior that may appear correct because the C++ compiler allows the program to executed, but has unexpected results.