C++ chapter 2
True/False: When writing long integer literals or long long integer literals in C++ 11, you can use either an uppercase or lowercase L.
True
True/False: Floating point constants are normally stored in memory as doubles.
True
Which data type typically requires only one byte of storage? a. short b. int c. float d. char e. double
d. char
How would you consolidate 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, y, z = 7, 16, 28 d. int x = 7, y = 16, z = 28; e. None of these will work
d. int x = 7, y = 16, z = 28;
What is the modulus operator? a. + b. * c. & d. % e. ||
d. %
True/False: The C++ language requires that you give variables names that indicate what the variables are used for.
False
A variable's ___________ is the part of the program that has access to the variable. a. data Type b. value c. scope d. reach e. None of the above
c. scope
What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl; a. 0 1 2 c. xyz b. 0 1 2 d. 012
d. 012
For every opening brace in a C++ program, there must be a: a. String literal b. Function c. Variable d. Closing brace e. None of the above
d. Closing brace
________ represent storage locations in the computer's memory. Question options: A) Literals B) Variables C) Comments D) Integers E) None of these
B) Variables
Which data type typically requires only one byte of storage? Question options: A) short B) char C) double D) float E) int
B) char
What will the value of x be after the following statements execute? Int x; x=18%4 Question options: A) 2 B) 0.45 C) 4 D) unknown
A) 2
These are data items whose values do not change while the program is running. Question options: A) Literals B) Variables C) Comments D) Integers E) None of these
A) Literals
Which character signifies the beginning of an escape sequence? Question options: A) \ B) { C) # D) // E) /
A) \
In a C++ program, two slash marks ( // ) indicate: Question options: A) The end of a statement B) The beginning of a comment C) The end of the program D) The beginning of a block of code
B) The beginning of a comment
A variable whose value can be either true or false is of this data type. Question options: A) binary B) bool C) T/F D) float E) None of these
B) bool
The _____ causes the contents of another file to be inserted into a program. a. Backslash b. Pound sign c. Semicolon d. #include directive e. None of the above
d. #include directive
In memory, C++ automatically places a ________ at the end of string literals. Question options: A) Semicolon B) Quotation marks C) Null terminator D) Newline escape sequence E) None of these
C) Null terminator
True/False: C++ 11 introduces an alternative way to define variables, using the template key word and an initialization value.
True
A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places.
ANS: F
C++ does not have a built in data type for storing strings of characters.
ANS: T
In the C++ instruction, cookies = number % children; given the following declaration statement: int number = 38, children = 4, cookies; what is the value of cookies after the execution of the statement? a. 2 b. 0 c. 9 d. .5 e. None of these
a. 2
This control sequence is used to skip over to the next horizontal tab stop. Question options: A) \n B) \h C) \t D) \a E) \'
C) \t
The ________ is/are used to display information on the computer's screen. Question options: A) Opening and closing braces B) Opening and closing quotation marks C) cout object D) Backslash E) None of these
C) cout object
Assume that a program has the following variable definition: char letter; Which of the following statements correctly assigns the character Z to the variable? Question options: A) letter = "Z"; B) letter = Z; C) letter = 'Z'; D) letter = (Z);
C) letter = 'Z';
These are data items whose values do not change while the program is running. a. Literals b. Variables c. Comments d. Integers e. None of the above
a. Literals
Character constants in C++ are always enclosed in ______. a. [brackets] b. "double quotation marks" c. 'single quotation marks' d. {braces} e. (parentheses)
c. 'single quotation marks'
The numeric data types in C++ can be broken into two general categories: a. numbers and characters b. singles and doubles c. integer and floating point d. real and unreal e. None of the above
c. integer and floating point
If you do not follow a consistent programming style, your programs will generate compiler errors.
ANS: F
The C++ language requires that you give variables names that indicate what the variables are used for.
ANS: F
A preprocessor directive does not require a semicolon at the end.
ANS: T
Escape sequences are always stored internally as a single character.
ANS: T
Floating point constants are normally stored in memory as doubles.
ANS: T
When typing in your source code into the computer, you must be very careful since most of your C++ instructions, header files, and variable names are case sensitive.
ANS: T
Which one of the following would be an illegal variable name? Question options: A) dayOfWeek B) itemsorderedforthemonth C) _employee_num D) 3dGraph E) Junē997
D) 3dGraph
The first step in using the string class is to #include the ________ header file. Question options: A) iostream B) cctype C) cmath D) string E) None of these
D) string
True/False: A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places.
False
True/False: If you do not follow a consistent programming style, your programs will generate compiler errors.
False
True/False: A preprocessor directive does not require a semicolon at the end.
True
True/False: C++ does not have a built in data type for storing strings of characters.
True
True/False: Escape sequences are always stored internally as a single character.
True
True/False: When typing in your source code into the computer, you must be very careful since most of your C++ instructions, header files, and variable names are case sensitive.
True
In programming terms, a group of characters inside a set of quotation marks is called a: a. String literal b. Variable c. Operation d. Statement e. None of the above
a. String literal
The float data type is considered _____ precision, and the double data type is considered _______ precision. a. single, double b. float, double c. integer, double d. short, long e. None of the above
a. single, double
What is the output of the following statement? cout << 4 * (15 / (1 + 3)) << endl; a. 15 b. 12 c. 63 d. 72 e. None of these
b. 12
Which one of the following would be an illegal variable name? a. dayOfWeek b. 3dGraph c. _employee_num d. Junē997 e. itemsorderedforthemonth
b. 3dGraph
Besides decimal, two other number systems you might encounter in C++ programs are: a. Octal and Fractal b. Hexadecimal and Octal c. Unary and Quaternary d. Base 7 and Base 9 e. None of the above
b. Hexadecimal and Octal
This is used to mark the end of a complete C++ programming statement. a. Pound Sign b. Semicolon c. Data type d. Void e. None of the above
b. Semicolon
In a C++ program, two slash marks ( // ) indicate: a. The end of a statement b. The beginning of a comment c. The end of the program d. The beginning of a block of code e. None of the above
b. The beginning of a comment
____________ must be included in any program that uses the cout object. a. Opening and closing braces b. The header file iostream c. Comments d. Escape sequences e. None of the above
b. The header file iostream
What will the following code display? int number = 7; cout << "The number is " << "number" << endl; a. The number is 7 b. The number is number c. The number is7 d. The number is 0
b. The number is number
_____________ represent storage locations in the computer's memory. a. Literals b. Variables c. Comments d. Integers e. None of the above
b. Variables
A variable whose value can be either true or false is of this data type. a. binary b. bool c. T/F d. float e. None of the above.
b. bool
You must have a ___________ for every variable you intend to use in a program. a. purpose b. definition c. comment d. constant e. None of the above
b. definition
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;
b. double payCheck;
Every complete C++ program must have a _____________. a. comment b. function named main c. preprocessor directive d. symbolic constant e. cout statement
b. function named main
Assume that a program has the following string object definition: string name; Which of the following statements correctly assigns a string literal to the string object? a. name = Jane; b. name = "Jane"; c. name = 'Jane'; d. name = (Jane);
b. name = "Jane";
If you use a C++ key word as an identifier, your program will: a. Execute with unpredictable results b. not compile c. understand the difference and run without problems d. Compile, link, but not execute e. None of the above
b. not compile
These are used to declare variables that can hold real numbers. a. Integer data types b. Real data types c. Floating point data types d. Long data types e. None of the above
c. Floating point data types
In memory, C++ automatically places a ___________ at the end of string literals. a. Semicolon b. Quotation marks c. Null terminator d. Newline escape sequence e. None of the above
c. Null terminator
A statement that starts with a # is called a: a. Comment b. Function c. Preprocessor directive d. Key word e. None of the above.
c. Preprocessor directive
Which character signifies the beginning of an escape sequence? a. // b. / c. \ d. # e. {
c. \
This control sequence is used to skip over to the next horizontal tab stop. a. \n b. \h c. \t d. \a e. \'
c. \t
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 the above
c. cout object
A character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________ quotation marks. a. double, single b. triple, double c. open, closed d. single, double e. None of the above
d. single, double
The first step in using the string class is to #include the ___________ header file. a. iostream b. cctype c. cmath d. string e. None of the above
d. string
Of the following, which is a valid C++ identifier? a. Junē997 b. _employee_number c. ___department d. myExtraLongVariableName e. All of the above are valid identifiers.
e. All of the above are valid identifiers.
Which escape sequence causes the cursor to move to the beginning of the current line? a. \n b. \t c. \a d. \b e. \r
e. \r
This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires. a. len b. bytes c. f(x) d. int e. sizeof
e. sizeof