Final Exam Review Flashcards
(49 cards)
A statement that starts with a # symbol is called a:
a. comment
b. function
c. keyword
d. preprocessor directive
d. preprocessor directive
These are data items that cannot have their value changed while the program is running:
a. variables
b. Constants and Literals
c. Floating point numbers
d. integers
b. Constants and Literals
Mark all of the following which are valid identifiers (Each mark is worth one point) :
a. TheLastPeriod.
b. 12Itemstoaddup
c. _start_of_the_block
d. SpecialCharacter!
e. TheSummaryTotal
f. reallyreallyreallylongvariable8675309
c, e, f
For every opening brace “{“ there must be a:
a. String Literal
b. Variable and semicolon
c. Function
d. Closing Brace “}”
d. Closing Brace “}”
In C++, two slashes “//” indicate :
a. Beginning of a statement
b. Preprocessor Directive
c. the end of a code block
d. The start of a Comment
d. The start of a Comment
What is the difference between a while loop and a do-while loop?
a. The while loop tests the entry condition after being executed at least once.
b. The wile loop is executed at least once. The do-while loop may not be.
c. There is no difference
d. The do-while loop is executed at least once, the while loop may or may not be executed once.
d. The do-while loop is executed at least once, the while loop may or may not be executed once.
What symbol is the modulus operator?
a. %
b. /
c. *
d. &
a. %
What is the output of the following statement?
cout «_space;4 * (15 / (1 + 3) «endl;
a. 15
b. 72
c. 63
d. 12
12
What is the mark or character at the end of every c++ statement?
a. # Pound sign or hashtag
b. . Period
c. , Comma
d. ; Semicolon
d. ; Semicolon
Given the definitions below, which statement(s) reads in two integer variables.
int var1,var2;
a. read»var1»var2;
b. cin»var1»var2;
c. read«var1«var2
d. cin«var1«var2;
b. cin»var1»var2;
Match the c++ data type to an example of the data that it can hold.
int, float, bool, char
true, a, 1024, 3.14159
int-1024
float-3.14159
bool-true
char-a
Given the following segment of code, what line of code contains a syntax error? ?
1 // This program displays my gross wages.
2 // I worked 40 hours and I make $20.00 per hour.
3 #include <iostream>
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 }</iostream>
a. Line 5, blank line
b. Line 9
c. Line 15
d. Line 14
b. Line 9
Which of the following correctly consolidates the following declaration statements into one statement?
int x=7;
int y=16;
int z=28;
a. int x=7, y=16, z=28;
b. int x=7 y=16 z=28;
c. int x=7; y=16; z=28;
d. int x,y,z = {7,16,28);
a. int x=7, y=16, z=28;
What will the following code display to standard output?
cout «“Four\n” «_space;“score\n”
cout«“and”«” \nseven”;
cout«“\nyears “«” ago”«endl;
a. Four score
andseven
years ago
b. Four score and seven years ago
c. Four
score
and
seven
years ago
d. fourscoreandsevenyearsago
c. Four
score
and
seven
years ago
What will be the value of x after the following statements are executed?
int x;
x = 18.0/4;
a. 4.5
b. 5
c. 4
d. 0
c. 4
The _____ operator always follows the cin object, and the _____ operator always follows the cout object.
a. «,»_space;
b. * , %
c.»_space; , «_space;
d. binary, unary
c.»_space; , «
In any program that uses the cin object, you must include the ________.
a. standard C library or #include <cstdlib.h>
b. compiler
c. linker
d. The iostream header file or #include <iostream></iostream></cstdlib.h>
d. The iostream header file or #include <iostream></iostream>
You can use these to override the rules of operator precedence in a mathematical expression.
a. [Square Brackets]
b. {curly brackets}
c. “Double Quotes”
d. (parenthesis)
d. (parenthesis)
In the following C++ statement, what will be executed first according to the order of precedence?
result = 6 - 3 * 2 + 7 - 10 / 2;
a. 3*2
b. 7-10
c. 2+7
d. 6-3
a. 3*2
In the iomanip library, this manipulator is used to establish the width for the value immediately following it.
a. fwidth() // field width
b. setf() // Set field
c. setw() // Set Width
d. setsize() // Set size
c. setw() // Set Width
What is true about the following statement?
cout «_space;setw(4) «_space;num4 «_space;” “;
a. It allows 4 spaces to print the value in num4
b. It prints out the number 4
c. It outptus setw(4) before the value in num4.
d. It outputs up to four ascii characters in num4
a. It allows 4 spaces to print the value in num4
Which of the following statements are equivalent to the following?
x = x * 2;
a. X = x * x;
b. X * =2 ;
c. x*x;
d. X * 2 ;
b. X *=2 ;
What will be the output of the following code segment after the user enters 0 at the keyboard?
int x = -1;
cout «_space;“Enter a 0 or a 1 from the keyboard: “;
cin»_space; x;
if (x)
cout «_space;“true” «_space;endl;
else
cout «_space;“false” «_space;endl;
a. false
b. x
c. true
d. nothing will be displayed
a. false
What is the output of the following code segment?
int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "That is all folks!" << endl;
a. This is false!
That is all folks!
b. This is true!
That is all folks!
c. That is all folks!
d. This is true!
This is false!
b. This is true!
That is all folks!