Final Flashcards
C++ not only supports OOP but also supports other programming styles. T or F
T
In C++ the variables Alpha, ALPHA and AlphA are the same identifier. T or F
F
In C++ the compiler will infer the type intended for a variable from the context in which the variable occurs. T or F
F
A C++ variable declaration includes a name and data type. T or F
T
A C++ declaration is a definition that also allocates storage for an identifier’s value (or function’s body etc.). T or F
T
C++ uses only / / for comments. T or F
F
Code, within the same block, after a return or a call to the exit function, will not be executed. T or F
T
It is legal to replace the prototype double totalCost(int numberParam, double priceParam); with the more terse, alternate form double totalCost(int, double); T or F
T
Extensive use of global variables is a satisfactory replacement for the difficulties of parameter passing with functions. T or F
F
A variable declared outside any function is said to be a local variable. T or F
F
Consider two blocks, one within another. If an identifier is declared as a variable in the inmost of these two blocks, one can access this variable from the outer block. T or F
F
Given the declaration
int x = 0;
The following expression causes a divide by zero error:
(x == 0) || (2/x < 1); T or F
F
In a while loop, the boolean expression is executed before each execution of the loop body. T or F
T
A break statement is used in loops only. T or F
F
When a loop is nested inside another loop, a break terminates the outermost loop of the nested loop structure. T or F
F
Curly braces are required around a single statement contained in a control structure. T or F
F
The range of values for an unsigned int variable is from about -4 billion to +4 billion. T or F
F
In C++, which of the following is a legal identifier?
a) 9xyz
b) @Xyz
c) X+yz
d) xy_z
e) a and d
D
Pick the word that is not a C++ keyword out of the following list.
a) while
b) boolean
c) double
d) if
e) none of the above
B
Which of the following types is not built into the C++ language:
a) bool
b) real
c) short
d) long
e) double
B
An l-value is
a) an expression that can be only be placed on the left of any operator such as +, * , /, etc.
b) assigned a value
c) can never have a value fetched from it
d) is designed for use by a left-handed person
B
The value of the expression 20.0 * (9/5) + 32.0 is
a) 68.0
b) 52.0
c) incorrect expression so there is no value
d) 32.0
e) incorrect expression , the / should be %
B
A call to a C++ function is
a) The name of the function followed by empty parentheses.
b) The name of the function followed by any number of arguments, regardless of the
number of parameters in the definition.
c) The name of the function followed by a number of arguments not greater than the number
of parameters in the definition.
d) The name of the function only.
e) none of the above
C
A void function
a) performs some action and returns a value
b) performs some action but does not return a value
c) is a statement
d) call is written much like a call to a value returning function but is terminated with a
semicolon.
e) may return a value but is not required to have one.
B
A definition of a variable outside any function is called a
a) local function definition
b) global variable definition
c) global function header
d) global function definition
e) local variable definition
B
Where can you not declare a variable in a C++ program?
a) Within the parameter list of a function definition
b) Within the block of a void function.
c) Within the argument list of a function call
d) Within a block nested within another block
e) Within the block of a value returning function.
C
Assume this code fragment is embedded in an otherwise correct and complete program. What should be the output from this code segment? { for( int i = 0; i < 10; i++) { .. . } cout << i << endl; } a) 10 b) 9 c) 0 d) The variable i is undefined in this scope, so this should not compile e) none of the above
D
What is the difference between executing the return 0; statement and its rough equivalent, a call to the exit(0); function, or the difference between return 1; and exit(1);?
a) These are very nearly equivalent anywhere they are encountered.
b) These are very different if encountered in a function other than main();.The exit function terminates the program, returning control to the operating system, whereas return only terminates the function, returning control to the calling function.
c) Both these return control to the free store manager by way of the exception controller, sending the argument as an error code.
d) none of the above
B
Given the following include directive (to get the declaration for the pow function from the math library):
#include
Now make these declarations:
double base = 2, exponent = 3, power = 4;
Which of the following are syntactically correct invocations for the pow function?
a) power = pow(base, exponent);
b) pow(power, base, exponent);
c) pow(base, exponent) = power;
d) base = pow(exponent, power);
e) both a and d
E
Which control construct repeats a sequence of statements zero or more times?
a) while statement
b) do-whilestatement
c) switch statement
d) if-elsestatement
e) none of the above
A
Which of the following is not true of the || operator?
a) It has two operands.
b) It can have one operand.
c) It is the logical OR operator.
d) It returns true if either operands is true.
e) It uses short circuit evaluation.
B
In a switch statement, when a break statement is encountered, an immediate transfer of control is made to
a) the default case of the switch statement
b) agotostatement
c) the else clause
d) the statement beyond the end of the switch statement.
e) none of these
D