Deck 2: Introduction to C
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/62
Play
Full screen (f)
Deck 2: Introduction to C
1
In a C++ program, two slash marks (//) indicate
A) the end of a statement
B) the beginning of a comment
C) the end of a program
D) the beginning of a block of code
E) None of these
A) the end of a statement
B) the beginning of a comment
C) the end of a program
D) the beginning of a block of code
E) None of these
B
2
For every opening brace ({) in a C++ program, there must be a
A) string literal
B) function
C) comment
D) closing brace
E) None of these
A) string literal
B) function
C) comment
D) closing brace
E) None of these
D
3
A named constant is like a variable, but it its content cannot be changed while the program is running.
True
4
In C++, key words are written in all lowercase letters.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
5
In C++ you are required to name your variables so they indicate the purpose they will be used for.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
6
A statement that starts with a hashtag (or pound) symbol (#) is called a
A) comment
B) function
C) preprocessor directive
D) header file
E) None of these
A) comment
B) function
C) preprocessor directive
D) header file
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
7
The preprocessor executes after the compiler.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
8
Escape sequences are always stored internally as a single character.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
9
The __________ causes the content of another file to be inserted into a program.
A) cout object
B) double slash (//)
C) #include directive
D) semicolon (;)
E) None of these
A) cout object
B) double slash (//)
C) #include directive
D) semicolon (;)
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
10
In programming, the terms "line" and "statement" always mean the same thing.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
11
C++ does not have a built-in data type for storing strings of data.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
12
Floating point constants are normally stored in memory as doubles.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
13
Programming style refers to the way a programmer uses elements such as identifiers, spaces, and blank lines.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
14
C++ 11 introduced an alternative way to define variables, using the template key word and an initialization value.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
15
The __________ is(are) used to display information on the computer's screen.
A) opening and closing braces
B) opening and closing quotation marks
C) cout object
D) backslash
E) None of these
A) opening and closing braces
B) opening and closing quotation marks
C) cout object
D) backslash
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
16
When typing your source code into the computer, you should be careful since most of your C++ instructions, header files, and variable names are case sensitive.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
17
Because C++ is case-sensitive, all programs must have a function called main or Main.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
18
A value is stored in a variable with an assignment statement.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
19
The preprocessor reads a program before it is compiled and only executes those lines beginning with # symbol.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
20
In the following statement, the characters Hello! are a(n) cout << "Hello!";
A) variable
B) string literal
C) comment
D) object
E) None of these
A) variable
B) string literal
C) comment
D) object
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
21
In C++11, if you want an integer literal to be treated as a long long int, you can append __________ at the end of the number.
A) L
B)
C) LONG LONG
D) LL
E)
A) L
B)
C) LONG LONG
D) LL
E)
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
22
What will the following code display?
Cout << "Roses " << "are red";
Cout << "and " << "violets/n"
Cout << "are" << "blue" << endl;
A) Roses are red
And violets
Are blue
B) Roses are red and violets/nare blue
C) Roses are redand violets/nareblue
D) Roses are red and violets/n are blue
Cout << "Roses " << "are red";
Cout << "and " << "violets/n"
Cout << "are" << "blue" << endl;
A) Roses are red
And violets
Are blue
B) Roses are red and violets/nare blue
C) Roses are redand violets/nareblue
D) Roses are red and violets/n are blue
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
23
What will the following code display?
Cout << "Monday";
Cout << "Tuesday";
Cout << "Wednesday";
A) Monday
Tuesday
Wednesday
B) Monday Tuesday Wednesday
C) MondayTuesdayWednesday
D) "Monday"
"Tuesday"
"Wednesday"
E) "Monday" "Tuesday" "Wednesday"
Cout << "Monday";
Cout << "Tuesday";
Cout << "Wednesday";
A) Monday
Tuesday
Wednesday
B) Monday Tuesday Wednesday
C) MondayTuesdayWednesday
D) "Monday"
"Tuesday"
"Wednesday"
E) "Monday" "Tuesday" "Wednesday"
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
24
What will the following code display?
Int x = 23, y = 34, z = 45;
Cout << x << y << z << endl;
A) 23 34 45
B) 23
34
45
C) xyz
D) 233445
Int x = 23, y = 34, z = 45;
Cout << x << y << z << endl;
A) 23 34 45
B) 23
34
45
C) xyz
D) 233445
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
25
Which control sequence is used to skip over to the next horizontal tab stop?
A) \n
B) end1
C) \t
D) \b
E) \'
A) \n
B) end1
C) \t
D) \b
E) \'
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
26
In a cout statement, which of the following will advance the output position to the beginning of the next line?
A) endl or \n
B) end1 or /n
C) \n or \t
D) \t or \b
E) \\ or \'
A) endl or \n
B) end1 or /n
C) \n or \t
D) \t or \b
E) \\ or \'
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following must be included in any program that uses the cout object?
A) opening and closing braces
B) the header file iostream
C) comments
D) a namespace
E) None of these
A) opening and closing braces
B) the header file iostream
C) comments
D) a namespace
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
28
Every complete C++ program must have a
A) comment
B) function named main
C) symbolic constant
D) cout statement
E) None of these
A) comment
B) function named main
C) symbolic constant
D) cout statement
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
29
Data items whose values do not change while the program is running are
A) literals
B) variables
C) characters
D) integers
E) None of these
A) literals
B) variables
C) characters
D) integers
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
30
The numeric data types in C++ can be broken into two general categories which are
A) numbers and characters
B) singles and doubles
C) integers and floating-point numbers
D) real and unreal numbers
E) numbers and literals
A) numbers and characters
B) singles and doubles
C) integers and floating-point numbers
D) real and unreal numbers
E) numbers and literals
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
31
What will the following code display?
Int number = 23;
Cout << "The number is " << "number" << endl;
A) The number is 23
B) The number is23
C) The number is number
D) The number is null
E) The number is
Int number = 23;
Cout << "The number is " << "number" << endl;
A) The number is 23
B) The number is23
C) The number is number
D) The number is null
E) The number is
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
32
A character literal is __________, whereas a string literal is __________
A) enclosed in quotation marks, enclosed in brackets
B) enclosed in brackets, enclosed in quotation marks
C) enclosed in double quotation marks, enclosed in single quotation marks
D) enclosed in single quotation marks, enclosed in double quotation marks
E) None of these
A) enclosed in quotation marks, enclosed in brackets
B) enclosed in brackets, enclosed in quotation marks
C) enclosed in double quotation marks, enclosed in single quotation marks
D) enclosed in single quotation marks, enclosed in double quotation marks
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
33
Besides the decimal number system that is most common (base 10), two other number systems that can be used in C++ programs are
A) octal and fractal
B) octal and hexadecimal
C) base 2 and base 4
D) base 2 and binary
E) None of these
A) octal and fractal
B) octal and hexadecimal
C) base 2 and base 4
D) base 2 and binary
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
34
You must have a _____________ for every variable you intend to use in a program.
A) purpose
B) variable definition
C) memory space
D) literal value
E) None of these
A) purpose
B) variable definition
C) memory space
D) literal value
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
35
Which data type typically requires only one byte of storage?
A) short
B) int
C) float
D) char
E) string
A) short
B) int
C) float
D) char
E) string
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following is not a valid C++ identifier?
A) April2018
B) employee_number
C) _1user
D) 1user
E) theLittleBrownFoxWhoRanAway
A) April2018
B) employee_number
C) _1user
D) 1user
E) theLittleBrownFoxWhoRanAway
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
37
A variable definition tells the computer
A) the variable's name and its value
B) the variable's data type and its value
C) the variable's name and the type of data it will hold
D) whether the variable is an integer or a floating-point number
E) None of these
A) the variable's name and its value
B) the variable's data type and its value
C) the variable's name and the type of data it will hold
D) whether the variable is an integer or a floating-point number
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
38
Character constants in C++ are always enclosed in
A) brackets ( < > )
B) braces ( { } )
C) single quotation marks ( ' ' )
D) pound sign and semicolon ( # ; )
E) Any of these
A) brackets ( < > )
B) braces ( { } )
C) single quotation marks ( ' ' )
D) pound sign and semicolon ( # ; )
E) Any of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
39
What will the following code display?
Cout << "Four\n" << "score\n";
Cout << "and" << "\nseven";
Cout << "\nyears" << " ago" << endl;
A) Four
Score
And
Seven
Years ago
B) Four score and seven
Years ago
C) Four
Score
And seven
Years ago
D) Four score
And seven
Years ago
Cout << "Four\n" << "score\n";
Cout << "and" << "\nseven";
Cout << "\nyears" << " ago" << endl;
A) Four
Score
And
Seven
Years ago
B) Four score and seven
Years ago
C) Four
Score
And seven
Years ago
D) Four score
And seven
Years ago
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
40
A(n) __________ represents a storage location in the computer's memory.
A) literal
B) variable
C) comment
D) integer
E) None of these
A) literal
B) variable
C) comment
D) integer
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
41
A multi-line comment
A) begins with /* and ends with */
B) can be used to mark as many lines as desired as comments
C) allows everything in the selected lines to be ignored
D) All of these are true
A) begins with /* and ends with */
B) can be used to mark as many lines as desired as comments
C) allows everything in the selected lines to be ignored
D) All of these are true
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
42
Assuming that a program has the following string object definition, which statement correctly assigns the string literal "Jane" to the string object?
String name;
A) name = Jane;
B) name = 'Jane';
C) name = "Jane";
D) name =;
E) string name = {Jane};
String name;
A) name = Jane;
B) name = 'Jane';
C) name = "Jane";
D) name =
E) string name = {Jane};
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
43
In memory, C++ automatically places a(n) __________ at the end of string literals which __________.
A) semicolon, indicates the end of the statement
B) \n, indicates an escape sequence
C) null terminator, marks the end of the string
D) bracket, marks the end of the string
E) None of these
A) semicolon, indicates the end of the statement
B) \n, indicates an escape sequence
C) null terminator, marks the end of the string
D) bracket, marks the end of the string
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
44
Which of the following statements correctly assigns the character M to the variable named letter?
A) letter = M
B) letter = "M";
C) letter = 'M';
D) letter = (M);
E) letter = M;
A) letter = M
B) letter = "M";
C) letter = 'M';
D) letter = (M);
E) letter = M;
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
45
The float data type is considered ___________ precision and the double data type is considered __________ precision.
A) single, double
B) double, single
C) floating-point, double
D) floating-point, integer
E) None of these
A) single, double
B) double, single
C) floating-point, double
D) floating-point, integer
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
46
The data type of a variable whose value can be either true or False is
A) int
B) binary
C) bool
D) Boolean
E) T/F
A) int
B) binary
C) bool
D) Boolean
E) T/F
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
47
What is the value of number after the following statements execute?
Int number;
Number = 18 % 4 + 2;
A) 3
B) 4
C) 6.5
D) 0
E) unknown
Int number;
Number = 18 % 4 + 2;
A) 3
B) 4
C) 6.5
D) 0
E) unknown
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
48
What is the value of cookies after the following statements execute?
Int number = 38, children = 4, cookies;
Cookies = number % children;
A) 2
B) 4
C) 9
D) 9.5
E) .5
Int number = 38, children = 4, cookies;
Cookies = number % children;
A) 2
B) 4
C) 9
D) 9.5
E) .5
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
49
What is the value stored in the variable myNum after the following assignment statement executes?
MyNum = 23 % 5
A) 3
B) 4
C) 4.6
D) 115
E) None of these
MyNum = 23 % 5
A) 3
B) 4
C) 4.6
D) 115
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
50
What is the value of number after the following statements execute?
Int number;
Number = 18 / 4;
A) 4.5
B) 4
C) 2
D) 0
E) unknown
Int number;
Number = 18 / 4;
A) 4.5
B) 4
C) 2
D) 0
E) unknown
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
51
Which of the following lines must be included in a program that has string variables?
A) #include (string class)
B) #include namespace std;
C) #include
D) string var;
E) None of these
A) #include (string class)
B) #include namespace std;
C) #include
D) string var;
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
52
The data type used to declare variables that can hold real numbers is
A) short
B) int
C) float
D) char
E) double
A) short
B) int
C) float
D) char
E) double
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
53
Which of the following statements correctly defines a named constant named TAX_RATE that holds the value 0.075?
A) double TAX_RATE = 0.075;
B) const TAX_RATE;
Double TAX_RATE = 0.075;
C) const double TAX_RATE = 0.075;
D) double TAX_RATE;
Const TAX_RATE = 0.075;
E) const TAX_RATE = 0.075;
A) double TAX_RATE = 0.075;
B) const TAX_RATE;
Double TAX_RATE = 0.075;
C) const double TAX_RATE = 0.075;
D) double TAX_RATE;
Const TAX_RATE = 0.075;
E) const TAX_RATE = 0.075;
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
54
A variable's __________ is the part of the program that has access to the variable.
A) data type
B) value
C) scope
D) assignment
E) None of these
A) data type
B) value
C) scope
D) assignment
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
55
What is output of the following statement?
Cout << 4 * (15 / (1 + 3)) << endl;
A) 15
B) 12
C) 63
D) 72
E) None of these
Cout << 4 * (15 / (1 + 3)) << endl;
A) 15
B) 12
C) 63
D) 72
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
56
Given the following program, which line(s) cause(s) output to be displayed on the screen?
1 // This program displays my gross wages.
2 // I worked 40 hours and I make $20.00 per hour.
3 #include
4 using namespace std;
5
6 int main()
7 {
8 int hours;
9 double payRate, grossPay;
10
11 hours = 40;
12 payRate = 20.0;
13 grossPay = hours * payRate;
14 cout << "My gross pay is $" << grossPay << endl;
15 return 0;
16 }
A) lines 13 and 14
B) lines 8 and 9
C) line 14
D) lines 14 and 15
E) line 15
1 // This program displays my gross wages.
2 // I worked 40 hours and I make $20.00 per hour.
3 #include
4 using namespace std;
5
6 int main()
7 {
8 int hours;
9 double payRate, grossPay;
10
11 hours = 40;
12 payRate = 20.0;
13 grossPay = hours * payRate;
14 cout << "My gross pay is $" << grossPay << endl;
15 return 0;
16 }
A) lines 13 and 14
B) lines 8 and 9
C) line 14
D) lines 14 and 15
E) line 15
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
57
What will be the output after the following lines of code execute?
Bool choice;
Choice = true;
Cout << "Your choice is " << choice << endl;
A) true
B) Your choice is true
C) Your choice is 1
D) Your choice is choice
E) None of these
Bool choice;
Choice = true;
Cout << "Your choice is " << choice << endl;
A) true
B) Your choice is true
C) Your choice is 1
D) Your choice is choice
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
58
Which part of the following line is ignored by the compiler?
Double userName = "janedoe"; // user's name is janedoe
A) "janedoe"
B) user's name is
C) user's name is janedoe
D) //
E) None of these
Double userName = "janedoe"; // user's name is janedoe
A) "janedoe"
B) user's name is
C) user's name is janedoe
D) //
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
59
Using C++11:
What data type does the compiler determine for the variable cost in the following statement?
Auto cost = 14.95;
A) int
B) double
C) bool
D) char
E) string
What data type does the compiler determine for the variable cost in the following statement?
Auto cost = 14.95;
A) int
B) double
C) bool
D) char
E) string
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
60
Which of the following defines a double-precision floating-point variable named payCheck?
A) float payCheck;
B) double payCheck;
C) payCheck double;
D) Double payCheck;
A) float payCheck;
B) double payCheck;
C) payCheck double;
D) Double payCheck;
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
61
Select all that apply. Which of the following statements is(are) true about named constants?
A) A named constant must be all uppercase.
B) The content of a named constant is read-only.
C) The value of a named constant cannot be changed while the program is running.
D) A named constant is defined using the const qualifier.
E) None of these
A) A named constant must be all uppercase.
B) The content of a named constant is read-only.
C) The value of a named constant cannot be changed while the program is running.
D) A named constant is defined using the const qualifier.
E) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
62
Select all that apply. Using C++11:
Which of the following can be used to initialize an integer variable named dozen with the value of 12?
A) int dozen = 12;
B) int dozen(12);
C) int dozen = {12};
D) int dozen = (12);
E) int dozen {12};
Which of the following can be used to initialize an integer variable named dozen with the value of 12?
A) int dozen = 12;
B) int dozen(12);
C) int dozen = {12};
D) int dozen = (12);
E) int dozen {12};
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck