Variables Flashcards

To understand Variables in C++

1
Q

What is Declaring?

A

When you set or declare the data type and name of the variable. These two properties of a variable do not change.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Assigning?

A

When you set the value of the variable. The value of a variable can change

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Accessing

A

When you retrieve the value of the variable by calling its
name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does each variable in C++ have?

A

It has
1. A data type
2. A name
3. A value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are integers?

A

Integers (also known as int ) are whole numbers. They can be positive or negative.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When writing large numbers, what must you NOT do?

A

You should NOT use a comma when typing large numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are Floating Point Numbers?

A

Floating Point Numbers (also known as float) are numbers with a decimal. They can be positive or negative.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The data type Float only uses 4 bytes? What is the better more sufficient option?

A

The more sufficient option is double which uses 8 bytes or double the space of a float.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What values can a boolean variable take?

A

A boolean variable (declared as a bool) can only take the value of true and false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the boolean value “true” equivalent to?

A

It is equivalent to 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the boolean value “false” equivalent to?

A

It is equivalent to 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens if you use the boolalpha command?

A

It prints the boolean value true/false instead of it’s association 1/0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a string?

A

A string is a collection of text, numbers or symbols. Strings are always surrounded by quotation marks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What isn’t visible when printing a string?

A

The quotation marks aren’t printed with the collection of text, numbers or symbols.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the 2 parts of declaring a variable?

A

You have to set or declare the data type and the name of the variable. These 2 properties do not change.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you declare a variable?

A

To declare a variable type the data type and the name of the variable, you want to create, and a ;

17
Q

When you run the code (string my_var;) what response does C++ give and why?

A

It sends back the message “ Command was successfully executed.” This is because no value has been assigned to the variable.

18
Q

When naming a variable, what must the starting character be?

A

The starting character must either be a letter or a underscore.

19
Q

What can the remainder of the variable name be?

A

The remainder of the variable name can be letters, numbers, or underscores.

20
Q

What set of words cannot be used as the variable name?

A

The C++ Keywords cannot be used as the name. For example, “my_class” is acceptable however “class” is not acceptable.

21
Q

What are C++ keywords?

A

C++ keywords are words that are reserved for specific functions or tasks within C++ programs.

22
Q

What is the name of the process of setting the initial value of a variable?

A

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.

23
Q

Since the value stored in the variable can change, what is this process called?

A

This process is called assigning or re-assigning.

24
Q

What is the assignment operator?

A

The assignment operator is “=” (the equals sign) which gives a variable a new value

25
Q

What code makes the integer variable “my_int” change from 123 to 321?

A

int my_int = 123;
cout « my_int « endl;
my_int = 321;
cout « my_int « endl;