Variables Flashcards
To understand Variables in C++
What is Declaring?
When you set or declare the data type and name of the variable. These two properties of a variable do not change.
What is Assigning?
When you set the value of the variable. The value of a variable can change
What is Accessing
When you retrieve the value of the variable by calling its
name.
What does each variable in C++ have?
It has
1. A data type
2. A name
3. A value
What are integers?
Integers (also known as int ) are whole numbers. They can be positive or negative.
When writing large numbers, what must you NOT do?
You should NOT use a comma when typing large numbers.
What are Floating Point Numbers?
Floating Point Numbers (also known as float) are numbers with a decimal. They can be positive or negative.
The data type Float only uses 4 bytes? What is the better more sufficient option?
The more sufficient option is double which uses 8 bytes or double the space of a float.
What values can a boolean variable take?
A boolean variable (declared as a bool) can only take the value of true and false.
What is the boolean value “true” equivalent to?
It is equivalent to 1
What is the boolean value “false” equivalent to?
It is equivalent to 0
What happens if you use the boolalpha command?
It prints the boolean value true/false instead of it’s association 1/0.
What is a string?
A string is a collection of text, numbers or symbols. Strings are always surrounded by quotation marks.
What isn’t visible when printing a string?
The quotation marks aren’t printed with the collection of text, numbers or symbols.
What are the 2 parts of declaring a variable?
You have to set or declare the data type and the name of the variable. These 2 properties do not change.
How do you declare a variable?
To declare a variable type the data type and the name of the variable, you want to create, and a ;
When you run the code (string my_var;) what response does C++ give and why?
It sends back the message “ Command was successfully executed.” This is because no value has been assigned to the variable.
When naming a variable, what must the starting character be?
The starting character must either be a letter or a underscore.
What can the remainder of the variable name be?
The remainder of the variable name can be letters, numbers, or underscores.
What set of words cannot be used as the variable name?
The C++ Keywords cannot be used as the name. For example, “my_class” is acceptable however “class” is not acceptable.
What are C++ keywords?
C++ keywords are words that are reserved for specific functions or tasks within C++ programs.
What is the name of the process of setting the initial value of a variable?
The name of the process is initialization. This process can be done separately after the declaration or you can also combine it into the same statement as the declaration.
Since the value stored in the variable can change, what is this process called?
This process is called assigning or re-assigning.
What is the assignment operator?
The assignment operator is “=” (the equals sign) which gives a variable a new value
What code makes the integer variable “my_int” change from 123 to 321?
int my_int = 123;
cout « my_int « endl;
my_int = 321;
cout « my_int « endl;