Chapter 1, Chapter 2, Chapter 3, Chapter 4, Chapter 5
The following contain several #include directives that may have problems. Which does not have one or more problems? Correct! a) #include b) #include ; c) #include "MyStream.h"; d) #include "cctype " e) #include "This file does not exist on the system"
a) #include
Given the definition and code fragment: int matrix[2][3]; int k = 0; for(int i =0; i < 3; i++) for (int j=0, j < 4; j++) matrix[i][j] = k++; The value of matrix[0][0] is a) 0 b) 1 c) 2 d) 3 e) 4
a) 0
What is the output of the following, if it were embedded in an otherwise correct and complete program and run? int x = 10; while (x > 0) { cout << x << " "; x = x + 3;} cout << endl; a) 10 13 16 19 . . . b) The compiler detects that this will be an infinite loop, so it does not compile. c) This is not an infinite loop. d) 0 3 6 9.
a) 10 13 16 19 . . .
Given the function, and the main function calling it: What is the output of the following code? (You are to assume this code is embedded in a correct function that calls it.): #include <iostream> using namespace std; void func(int x, int & y) {int t = x;x = y;y = t;} int main() {int u = 3; v = 4; // ... cout << u << " " << v << endl; func ( u, v ) cout << u << " " << v << endl; // ... } a) 3 4 3 3 b) 3 4 4 3 c) 3 4 3 4 d) 3 4 4 4
a) 3 4 3 3
The value of the expression 20.0 * (9.0/5) + 32.0 is a) 68.0 b) 52.0 c) expression has a syntax error so there is no value d) 32.0 e) an incorrect expression, the / should be %
a) 68.0
Which of these remarks about formal parameters is correct? a) A formal parameter is a kind of place holder that is filled with the argument at the time of call to the function b) A call-by-value formal parameter is a global variable that is initialized to the value set just before the function is called c) A call-by-reference formal parameter is modeled on a substitution mechanism. The argument should be an expression, not a variable, since there is never a need to assign such a variable d) The double && (ampersand) character is used to indicate call-by-reference. This is done by placing the & after the type name which is followed by the parameter name in the definition of the parameter in the function header e) The argument corresponding to a call-by-value parameter cannot be changed by a limited number of actions that may happen in the function call
a) A formal parameter is a kind of place holder that is filled with the argument at the time of call to the function
In C++ array indices, that is subscript values, must be a) An integer type b) Positive c) Less than or equal to the declared size of the array d) None of these is correct
a) An integer type
The statements int x = 1; int y; y = x++; do not... a) Assign y the value 2; b) Change the value of x to 2. c) Assign y the value 1; d) The ++ is a postfix operator.
a) Assign y the value 2;
The person responsible for the initial development of C++ was a) Bjarne Stroustrup b) Guido Van Rossum c) Patrick Ritchie d) James gosling
a) Bjarne Stroustrup
With regard to default arguments: a) Zero or more call-by-value parameters in a function may have default arguments b) All value parameters must have default arguments c) If a function has a reference parameter, no parameters to the right of the reference parameter may have default arguments d) If a parameter is missing a default argument, no parameters to the left of this point may have a default argument e) Reference parameters can have default arguments
a) Zero or more call-by-value parameters in a function may have default arguments
A formal parameter is ___________ . a) a local variable that is initialized to the value of its corresponding argument b) a global or local variable that is initialized to the value of a reference parameter that is passed in when the function is run c) a global variable that is initialized to the value of a reference parameter that is passed in when the function is run d) a local variable that is initialized to the value of a reference parameter that is passed in when the function is run
a) a local variable that is initialized to the value of its corresponding argument
C++ predefined functions... a) are usually provided in libraries b) make C++ harder than necessary c) don't usually require a header file d) are usually not provided with the C++ compiler
a) are usually provided in libraries
In the case of a void function the return statement ___________ any expression for a value returned and any return statement _________ . a) doesn't need, simply ends the function call b) handles, results in a value being sent back the next line after the last function call. c) automatically generates, simply ends the function call d) doesn't need, results in a value being sent back the next line after the last function call
a) doesn't need, simply ends the function call
fabs is the C++ abbreviation for ___________ . a) floating point absolute value b) floating point double value c) floating point integer value d) floating point long value
a) floating point absolute value
Default arguments should simply be listed _____________ . a) in the function declaration b) in the function definition c) in the function body d) in the function call
a) in the function declaration
Which of these array definitions will not set all the indexed variables to 0? a) int array[5]; b) int array[5] = {0,0,0}; c) int array[5] = {0}; d) int array[5] = {0,0,0,0,0};
a) int array[5];
Which of the following array initializations is not correct? a) int x[4] = {8, 7, 6, 5, 4}; b) int x[] = {8, 7, 6, 5, 4}; c) int x[4] = {8, 7, 6}; d) const int SIZE =4; int x[SIZE];
a) int x[4] = {8, 7, 6, 5, 4};
An enumeration type a) is type whose values are defined by a list of constants of type int. b) is not a type separate from any of the integer types c) cannot be converted to integer types d) is not a type that a programmer should avoid doing arithmetic with.
a) is type whose values are defined by a list of constants of type int.
A return statement consists of a ________ followed by an _________ . a) keyword 'return', expression b) curly bracket, semicolon c) reserved word 'return', variable name d) set of parameters in parenthesis, semicolon
a) keyword 'return', expression
The primary difference between an argument and a parameter is that an argument is __________ . a) normally the value passed into the formal parameter upon the function call b) there isn't any real difference and the terms may be used interchangeably without worrying about confusing other people at all c) automatically applied to the correct formal parameter regardless of the positional logic d) assigned its position in the function definition and must be applied accordingly
a) normally the value passed into the formal parameter upon the function call
It is not true that 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) A void function may have a return statement but is not required to have one
a) performs some action and returns a value
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 is a correct invocation for the pow function? a) power = pow(base, exponent); b) pow(power, base, exponent); c) pow(base, exponent) = power; d) base = pow(exponent, power)
a) power = pow(base, exponent);
C++ functions are typically either _______ or _________ . a) predefined, programmer defined b) int, void c) defined, standard d) predefined, standard
a) predefined, programmer defined
Which of the following function declarations with default arguments are correct? a) void g(int length, int width, int height = 1); b) void g(int length=1, int width, int height); c) void g(int length, int width=1, int height); d) void g(int length=1, int width=1, int height);
a) void g(int length, int width, int height = 1);
Which of the following is a C++ keywords? a) while b) total c) doubleBlindTest d) IntegerNumbersOnly
a) while
Array indexes always start with _______ . a) zero 0 b) one 1 c) any positive integer value d) any variable name that has been properly declared and initialized
a) zero 0
In the expression (j > 0 && j+1 == 10), which operator executes last? a) > b) && c) + d) ==
b) &&
In distinguishing an expression as true or false, C++ sees which of the following as not true? a) true b) 0 c) 1 d) Any non-zero value e) The character 'F'
b) 0
Given the function, and the main function calling it: Which, if any, of the following choices is the output of the following code? #include <iostream> using namespace std; void func ( int& x, int & y) {int t = x;x = y;y = t;} int main() {int u = 3; v = 4; // ... cout << u << " " << v << endl; func ( u, v ) cout << u << " " << v << endl; // ... } a) 3 4 3 3 b) 3 4 4 3 c) 3 4 3 4 d) 3 4 4 4
b) 3 4 4 3
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) 52.0
Which of the following statements about the definition and declaration of functions is not correct? a) Function declaration is exactly the same as function prototype b) Function definition is exactly the same as function prototype c) A function header is exactly the same as function prototype except for the semicolon d) A function definition is a function header followed by the function block e) A function header syntax is the following: return_type function_name parenthesized_parameter_list
b) Function definition is exactly the same as function prototype
Which of the following is not true of the && operator? a) It has two operands. b) It can have one operand. c) It uses short circuit evaluation. d) It is the logical AND operator.
b) It can have one operand.
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) It can have one operand.
What does it mean when we say a programmer using a function should be able to treat the function like a black box? a) This is meaningless. One must know how a function does its job to effectively use it b) One must be able to rely on the description of the preconditions (requirements for use of the function) and the postconditions (promise of behavior to use the function) c) If one codes an application that uses a function with a knowledge of the internal mechanism of that function, then when the function's maintainer changes its internal mechanism, the application programmer could be faced with changing the application code extensively d) The most efficient programs are the ones that each function is designed to maximally use the internal behavior of every other function to speed up the code
b) One must be able to rely on the description of the preconditions (requirements for use of the function) and the postconditions (promise of behavior to use the function)
Which of the following determines the operator that is processed prior to another operator? a) Operator associativity b) Operator precedence c) Whether the operator is an arithmetic operator d) None of these determine the order in which operators are processed.
b) Operator precedence
Consider the function void doStuff(int parValue, int& parRef) { parValue = 100; cout << "parValue in call to doStuff = "<< parValue << endl; parRef =222; cout << "parRef in call to doStuff = " << parRef << endl; } and consider the call, which we assume is in a complete and correct program int n1 = 1, n2 =2; doStuff(n1, n2); a) The call to doStuff results in the assignment n1 = 222 b) The call to doStuff results in the assignment n2 = 222 c) The call to doStuff results in the assignment n1 = 100 d) The call to doStuff results in the assignment n2 = 100 e) There is no effect on either of these variables
b) The call to doStuff results in the assignment n2 = 222
The following are not true about the expression left && right. a) The expression is false when left is false and right is false b) The expression is true when left is true and right is false c) The expression is false when left is false and right is true d) The expression is true when left is true and right is true
b) The expression is true when left is true and right is false
The fundamental rule for testing functions requires that every function be tested in an already fully tested and debugged program. How can this be accomplished? a) Impossible! The main function must have all the functions it calls attached to get it to compile and run properly b) The main function is tested with stub functions replacing each` function c) Write drivers for the stub functions to test them d) Add the non-stub functions for testing in groups of no more than four at a time e) Write a driver for the function implementations and test them simultaneously
b) The main function is tested with stub functions replacing each` function
This question asks about nesting of if, if-else, switch, while, do-while, and for statements: a) These constructs may not be nested in at all. b) These constructs may be nested in any way that meets the needs of algorithms the programmer is coding. c) Only control constructs of a given kind may be nested (while loops within while loops; if-else within if-else etc.) d) The question does not make sense in C++.
b) These constructs may be nested in any way that meets the needs of algorithms the programmer is coding.
In C++, which of the following are legal identifiers? a) 9xyz b) XxXx c) X+Y-x d) x!y
b) XxXx
Every array declaration must have_________ . a) a stated base type, the size of the array, the name of the array b) a stated base type, the name of the array, the array literal c) a stated base type, the name of the array, the value to be stored at each indice d) the name of the array, the value to be stored at each indice, the size of the array
b) a stated base type, the name of the array, the array literal
Given the array declaration, int a[20]; The first element is written as: a) a[1] b) a[0] c) a d) a[20] e) a[19]
b) a[0]
A call by reference parameter is indicated by __________ . a) appending the & sign to the parameter variable declaration within the function body and before it is used b) appending the & sign to the paramater data type in the function declaration c) changing the value of a local variable in the body of a function d) changing the value of a global variable in the body of a main{} function
b) appending the & sign to the paramater data type in the function declaration
A void function can have a) no arguments b) as many arguments as there parameters c) no more than 3 arguments d) exactly one argument
b) as many arguments as there parameters
A 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) assigned a value
You can use ___________ as arguments to functions. a) indexed variables whether they are of the same data type as the function or not b) complete arrays as long as the indexed variables are of the same data type as the function c) complete arrays with their indexed variables listed separately d) neither arrays or indexed variables
b) complete arrays as long as the indexed variables are of the same data type as the function
One way to make your programs more versatile is to use _________ for the size of each array you use. a) the same number b) defined constant c) a very large number that is surely more than the size of any array you may ever need d) a sensibly large number that is surely larger than any array you may ever make
b) defined constant
In c++ there are three abs (absolute value) functions. If you want to produce a value of type long you should use labs, if you want to produce a value of type int use abs, and if you want to produce a value of type double use _______ . a) dabs b) fabs c) tabs d) ddabs
b) fabs
Which control construct repeats a sequence of statements zero or more times? a) do-while statement b) for statement c) switch statement d) if-else statement
b) for statement
What is the output of the following code (assuming it is embedded in a correct and complete program)? char letter[5] = {'o', 'k', 'c', 'e', 'g'}; for(int i = 4; i >= 0; i-- ) cout << letter[i]; cout << endl; a) okceg b) gecko c) ecko followed by a character from an out of bounds access d) kceg followed by a character from an out of bounds access e) Correct answer not listed
b) gecko
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) global variable definition
A function definition consists of a function ______ followed by a function _____. a) declaration, parameters b) header, body c) prototype, declaration d) identifiers, formal parameters
b) header, body
A global named constant _________________ . a) is declared at the beginning of the program and inside of the main function b) is declared at the beginning of the program and outside the body of any function. c) is declared just before it is used as an argument in a function call d) can be easily changed within any function and the changed value is simply returned out of the function into the global constant
b) is declared at the beginning of the program and outside the body of any function.
Consider the function definition and array declarations. Which is a correct call to the function make_2? void make_2 ( int a[], int size ) { for (int i = 0; i < size; i++ ) a[i] = 2; } int array1[20]; a) make_2( array1, 30 ); b) make_2( array1, 10 ); c) "Hey, make_2, come change array1. Its size is 20." d) make_2( array2[5],50 );
b) make_2( array1, 10 );
The main function in your program ____________ . a) doesn't need a return and if it does it doesn't have to be anything specific b) needs a return for the sake of portability and should always be of type int c) should always be called using 'main()' d) should always be called using 'main();'
b) needs a return for the sake of portability and should always be of type int
Which of the following types are not built into the C++ language: a) bool b) real c) short d) int e) double
b) real
Every array in C++ has three parts that are________ . a) the base type, the address in memory of each indice, the size of the array in bytes b) the base type, the address in memory of the [0] variable value, the size of the array c) the type of each array varaible, the address in memory of each indice, the size of the array in integers d) the type of each array varaible, the address in memory of the last indice, the size of the array
b) the base type, the address in memory of the [0] variable value, the size of the array
In C++ the array literal is __________ . a) the curly bracket {} b) the square bracket [] c) the parenthesis () d) the double quotation " "
b) the square bracket []
Which of the following are likely to be poor choices for an identifier in a program? a) votingRate b) x c) myData d) extraTimer
b) x
The preprocessor directives used with the assertion macros is/are a) #include ,#include b) #define NDBUG ,#include c) #include ,#define NDBUG d) #include ,#include e) #include ,#define NDBUG
c) #include ,#define NDBUG
Where is it legal to put a break statement? a) A break is placed in a nested loop, to terminate the loop. b) A break is placed in an inner block of nested blocks, to transfer control beyond the end of block the break is within. c) A break is placed in a loop in nested loops, to transfer control beyond the end of the innermost loop the break is within. d) A break is placed in a switch statement, to activate the switch by transferring control beyond the end of the switch. e) A break is placed in a loop where it restarts the loop.
c) A break is placed in a loop in nested loops, to transfer control beyond the end of the innermost loop the break is within.
What do the calls to exit(...) do when exit(0) and exit(1) are called? a) The exit( ) function stops the program. The argument is discarded b) The exit( ) function is obsolete. There is no longer any such function in the C++ libraries c) The exit( ) function stops the program. The argument is passed to the operating system which uses it for an error code d) The exit( ) function temporarily stops the program, and sends the argument to the operating system which uses it for an error code. The operating system restarts the program after fixing the error e) The exit( ) function allows the systems programmer to escape when the power supply catches fire
c) The exit( ) function stops the program. The argument is passed to the operating system which uses it for an error code
Which of the following are not true about the expression left || right. a) The expression is false when left is false and right is false b) The expression is true when left is true and right is false c) The expression is false when left is false and right is true d) The expression is true when left is true and right is tru
c) The expression is false when left is false and right is true
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 the same 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) These are very nearly equivalent when executed in the main function. In main, these both terminate main and send a success code to the operating system, returning control to the operating system d) Both these return control to the free store manager by way of the exception controller, sending the argument as an error code
c) These are very nearly equivalent when executed in the main function. In main, these both terminate main and send a success code to the operating system, returning control to the operating system
What is the value of the bool valued expression, 1 a) This statement is incorrect as it is always false. b) This statement is correct and its value depends on x. c) This statement is incorrect and it is always true d) This statement is incorrect, but it does depend on the value of x.
c) This statement is incorrect and it is always true
Which of these remarks about overloading a function name is correct? a) C++ distinguishes between function overloaded implementations by examining differences in return types. C++ distinguishes between overloaded function versions by examining differences in the argument lists b) C++ does not support function name overloading c) To decide which version of overloaded functions, C++ looks first for an exact match in the argument list types and the parameter list types d) If there is no match between the argument list types and the parameter list types C++ expects the programmer to supply type conversions to get a match.
c) To decide which version of overloaded functions, C++ looks first for an exact match in the argument list types and the parameter list types
When you don't recall operator precedences you can a) Look in a table of precedences b) Guess c) Use parentheses d) Experiment with the compiler
c) Use parentheses
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) Within the argument list of a function call
A semicolon (usually) goes after which of these? a) while(condition) b) if(condition) c) a function header to make it a function declaration d) int main( )
c) a function header to make it a function declaration
An r-value (is) a) an expression that can be only placed on the right of any operator such as +, *, / etc. b) can never be assigned a value c) anything that can be placed on the right hand side of the assignment operator d) is designed for use by a right-handed person.
c) anything that can be placed on the right hand side of the assignment operator
A formal parameter for an entire array is referred to as an.... a) call-by-reference parameter b) call-by-value parameter c) array parameter d) it is not a formal parameter
c) array parameter
Given the array declaration:int b[5];the last index in the array would be properly accessed by the statement... a) 6 = b[4] b) b[5] = 6 c) b[4] = 6 d) 5 = b[4]
c) b[4] = 6
One way to write a good function declaration comment is to break it down into a precondition and a postcondition. The precondition ________, and the postcondition __________ . a) sets the initial conditions as boolean true or false, describes the effect of the function call b) clearly states what is assumed to be true when the function is called, states what the ending condition will be as either boolean true or false c) clearly states what is assumed to be true when the function is called, describes the effect of the function call d) sets the initial conditions as boolean true or false, states what the ending condition will be as either boolean true or false
c) clearly states what is assumed to be true when the function is called, describes the effect of the function call
Which of the following loop statements is guaranteed to iterate the body of the loop at least once? a) while(control) body; b) for (initialize; test; update) body; c) do body while(control); d) all of the above e) none of the above
c) do body while(control);
Suppose you have the following array declaration in a program. int yourArray[5]; Further suppose that in the implementation of C++ you are using an int that requires 4 bytes. i) When your program runs, how much memory is required for this array? ii) Suppose further that your array starts at memory location decimal 100. What will be the address of yourArray[3]? iii) If you wrote to the (illegal) index 7 position in yourArray to what address would this clobber? a) i) The array takes 5 bytes, ii) yourArray[3] will be an int located at Address 103. iii) writing to yourArray[7] will clobber an int starting at location 107 b) i) The array takes 10 bytes, ii) yourArray[3] will be an int located at Address 106. iii) writing to yourArray[7] will clobber an int starting at location 114 c) i) The array takes 20 bytes, ii) yourArray[3] will be an int located at Address 112 iii) writing to yourArray[7] will clobber an int starting at location 128 d) The purpose of a high level language is to insulate the programmer from these details. It isn't possible to know this without probing the source to the operating system and the compiler, or extensive debugging
c) i) The array takes 20 bytes, ii) yourArray[3] will be an int located at Address 112 iii) writing to yourArray[7] will clobber an int starting at location 128
If your program uses a predefined function from some library, then it must contain an ________ statement that names that ________ . a) include pointer, library b) include pointer, function name c) include directive, library d) include directive, function name
c) include directive, library
Before a variable in C++ is used, it must be a) begin with a capital letter b) used in some expression c) initialized d) defined e) contain only letters, digits and underscores
c) initialized
Which of the following are correct? When a function having an array formal parameter is called, the formal array parameter ... a) names a copy of the array argument. b) refers to exactly the same array as the calling program c) is passed the address of the argument, and the function needs further information about the array size to safely use an array parameter d) refers to the array using a name that is always different from the calling program's argument.
c) is passed the address of the argument, and the function needs further information about the array size to safely use an array parameter
Consider the following function and code segment. void One( int first, int & second ) { first = 17; second = first + 1; } int main() {// other code ... int j = 4;int k = 3; One(j, k) ; // other code .. } After the call to One(j, k); what are the values of j and k? a) j == 4, k == 3 b) j == 17, k == 18 c) j == 4, k == 18 d) j == 17, k == 3
c) j == 4, k == 18
The comma operator a) is not a list of expressions separated by commas b) according to the ANSI C++ Standard, is supposed to be evaluated right to left c) not all compilers evaluate left to right, i.e., do not follow the C++ Standard, hence left to right evaluation should not be depended upon. d) has value equal to the value of the first expression in the list. e) all of the above
c) not all compilers evaluate left to right, i.e., do not follow the C++ Standard, hence left to right evaluation should not be depended upon.
In C++, a variable that has been defined but not initialized may a) be used in any way any identifier can be used. b) not be used at all c) not be used as an l-value d) not be used as an r-value e) have its value fetched prior to assignment
c) not be used as an l-value
Which of the following are not names of a C++ library function: a) abs b) sqrt c) random d) floor e) labs
c) random
A void function performs some action but does not _________ and is _________ . a) return a value, not a statement b) require an include statement, not a statement c) return a value, terminated with a semicolon d) require an include statement, terminated with a semicolon
c) return a value, terminated with a semicolon
All of the variables of any given array are of the ________ and that type is called the _________ . a) same type, initialized type b) initialized type, declared type c) same type, base type d) declared type, initialized type
c) same type, base type
Which of the following overloadings will be invoked by this call?g(1,2) a) int g(int count, double value); b) void g(double value, int count); c) void g(int value, int count); d) the compiler cannot decide which of these to use
c) void g(int value, int count);
If you put assert macros throughout your code, a) You have to put up with the resulting inefficiency and program halts with messages indecipherable to the user until you edit your code to remove them. b) You can put #define NDEBUG in your code in the file just after the #include directive c) you can define NDEBUG for the compile session by using an IDE menu option or you can use the compiler command line option -DNDEBUG
c) you can define NDEBUG for the compile session by using an IDE menu option or you can use the compiler command line option -DNDEBUG
Which of the following code fragments gives a random double value between 2 and 5 inclusive? You can assume that the random number seed has been set and any needed definitions and initializations have been made. a) 3.0*rand() + 2 b) 3.0*(RAND_MAX-rand())/RAND_MAX + 2 c) ((RAND_MAX-rand())/static_cast(RAND_MAX))*3 + 2 d) (RAND_MAX-rand())/static_cast(RAND_MAX)*5 -2 e) rand()/static_cast(RAND_MAX)*2 + 3
d) (RAND_MAX-rand())/static_cast(RAND_MAX)*5 -2
If this code fragment were executed in an otherwise correct and complete program, what would the output be? int a = 3, b = 2, c = 5; if (a > b) a = 4; if ( b > c) a = 5; else a = 6; cout << a < endl; a) 3 b) 4 c) 5 d) 6 e) None of the above, the cout statement belongs to the else and so is skipped.
d) 6
Why does this version of the swap function fail to work? void swap(int & lhs, int& rhs) { lhs = rhs; rhs = lhs; } a) Of course it works! Just look at it. It clearly swaps the two parameters b) It fails because the programmer forgot to make the parameters call-by-reference c) It fails OK, and we can fix it we can just reverse the order of the lines d) It fails because the first line destroys the old value of lhs without saving it. Then both variables have the old value of rhs in them, save the lhs value in a local variable before making the first assignment indicated, then instead of the second line, assign the rhs the value of the local variable
d) It fails because the first line destroys the old value of lhs without saving it. Then both variables have the old value of rhs in them, save the lhs value in a local variable before making the first assignment indicated, then instead of the second line, assign the rhs the value of the local variable
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 followed by exactly the number of arguments as there are parameters in the definition e) The name of the function only
d) The name of the function followed by exactly the number of arguments as there are parameters in the definition
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
d) The variable i is undefined in this scope, so this should not compile
If the following code fragment is executed in an otherwise complete and correct program, which expression will be executed? x = 0; if (x = 12) yes_statement; else no_statement; a) The no_statement will be executed because x is not 12. b) The statement has incorrect syntax so will not compile at all. c) x=12 is illegal in the Boolean expression of an if statement. d) The yes_statement will be executed.
d) The yes_statement will be executed.
Consider the if statement: if(condition) yes_clause; else no_clause; Under which of the following circumstances will both the yes_clause and the no_clause will be executed? a) When the condition is true. b) When the condition is false. c) When the condition is ambiguous. d) This will not happen.
d) This will not happen.
Which of the following does the C++ language not support? a) support for object oriented programming b) classes c) global functions d) automatic garbage collection e) traditional programming techniques
d) automatic garbage collection
When your program is run the main function is __________ . a) not called unless it is needed b) called by the statement 'main()' c) called by the statement 'main();' d) automatically called and may call other functions
d) automatically called and may call other functions
The two basic types of parameters are __________ and ___________ . a) global, local b) mixed, formal c) mixed, swap value d) call-by-value, call-by-reference
d) call-by-value, call-by-reference
Here is a small program. Which of the statements about the variables is correct? #include const double NUM = 2.9345358; double num = 3; double numTimes(int x); int main( ) {using namespace std; int value; cout << "Enter a value, I'll multiply it by " << NUM << endl; cin >> value; cout << "You entered " << value << " NUM times this is " << numTimes(value) << endl; return 0;} double numTimes(int x){double d; d = NUM * x; return d;} a) NUM is a local constant variable b) num is a global constant c) value is local variable in the main function d) d is a local variable in the numTimes function
d) d is a local variable in the numTimes function
The number of indexed variables in an array is called the __________ of the array. a) length b) range c) base type d) declared size
d) declared size
A __________ describes how the function computes the value it returns. a) function declaration b) function body c) function header d) function definition
d) function definition
Giving two or more function definitions the function name is called ________ . a) aliasing b) real bad coding and programming c) object overloading d) function overloading
d) function overloading
Usually all you need to do to use a library is to place an _______ directive and a _______ directive for that library in the file with your program. a) include, namespace b) using, namespace c) standard, namespace d) include, using
d) include, using
The variables used in any particular function are called ________ . a) global variables b) declared variables c) parameter arguments d) local variables
d) local variables
When a variable is given as a call-by-reference argument to a function it is the ______________ that is actually given to the calling function. a) declared variable name b) value of the variable according to its initialization c) stored binary value ib bytes d) memory address of the variable
d) memory address of the variable
Once you have properly declared an arry the computer ___________ . a) only remembers the last array indice value b) remembers only the array indice values c) remembers all of the array indice addresses d) only remembers the a[0] address
d) only remembers the a[0] address
Which of the following control structures requires curly braces? a) if-else b) while c) do-while d) switch e) for
d) switch
Which of the following overloadings will be invoked by this call?g(1.0,2.0); a) int g(int count, double value); b) void g(double value, int count); c) void g(int value, int count); d) the compiler cannot decide which of these to use
d) the compiler cannot decide which of these to use
The primary difference between a function declaration and a function definition is that ___________ . a) the function declaration does not require a semicolon at the end of the statement b) the function definition goes at the beginning of the program before the int main{} function c) there isn't any big difference between the two because they are the same thing d) the function definition must always have the formal parameter names
d) the function definition must always have the formal parameter names
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) a goto statement c) the else clause d) the statement beyond the end of the switch statement. e) none of these
d) the statement beyond the end of the switch statement.
Concerning return statements that functions can have: a) Value returning functions can have the statement: return (any computed_value); b) void functions can have the statement: return void; c) void functions must have a return; statement, with no argument. d) void functions may terminate using a return; statement without an argument, or they may have no return statement at all, terminating by falling off the end of the function block.
d) void functions may terminate using a return; statement without an argument, or they may have no return statement at all, terminating by falling off the end of the function block.
It is not true that a C++ predefined function a) argument is the value the predefined function starts with b) may be called any number of times in a program. c) computed value is the return value d) call is an expression that has the type specified as the return type of the function and can be used anywhere any other expression of that type could be used. e) #include is all that is ever necessary to provide access.
e) #include is all that is ever necessary to provide access.
Where is it legal to put a continue statement? What does the continue statement do there? a) A continue statement causes an nested loop to restart. b) A continue statement causes a loop to halt. c) A continue statement in a loop nested in another loop causes the entire nested loop to restart. d) A continue statement in switch statement transfers control to the top of the switch. e) A continue statement in a nested loop causes that loop to restart, there is no effect on other loops.
e) A continue statement in a nested loop causes that loop to restart, there is no effect on other loops.
Given the function definition, with arguments 7and 2.0 when the function was called, which of the following are correct? int func(int n, double d) {int j = n; double sum = 0; while( j >= 0) {sum += d; --j; } return sum;} a) returns 7*2 b) returns 7+2 c) returns 7! d) There is a syntax error in the program so it won't run. e) It compiles but computes none of these.
e) It compiles but computes none of these.
Which of these "properties" of testing using stubs and drivers are correct? a) Using drivers and stubs is a lot of work for not much gain b) Using drivers and stubs won't prevent having to debug a large program all at once c) Testing the pieces is difficult to do in any significant way. You need the entire program to run a meaningful test d) Drivers run the pieces individually. They are permanent. They can be minimal, without i/o, having only data generating code, and not doing much (except possibly validating) with the information they return e) Stubs are short programs that are fairly easy to write. They return only minimum data necessary for the caller to be debugged
e) Stubs are short programs that are fairly easy to write. They return only minimum data necessary for the caller to be debugged
Indicate which of these remarks about function parameters and arguments is correct. a) Arguments are listed in the function header between parentheses following the function name b) The word parameter should never be used as shorthand for formal parameter c) Formal parameters appear in a function call between parentheses following the function name d) Arguments are something that is used to fill in a reference parameter value e) The first argument fills in the first formal parameter, the second argument fills in the second formal parameter and so on
e) The first argument fills in the first formal parameter, the second argument fills in the second formal parameter and so on
Given the array declaration, int a[20]; The last (legal) element is written as: a) a[2] b) a[0] c) a d) a[20] e) a[19]
e) a[19]
It true that an assertion a) is never more than just comment embedded in code b) are always easily and precisely stated with C++ syntax, c) is never used to document and check correctness in programs d) is not typically a precondition or postcondition for a function e) if converted to a Boolean statement, may be used with the library assert macro to test whether the assertion is satisfied at that point in the code.
e) if converted to a Boolean statement, may be used with the library assert macro to test whether the assertion is satisfied at that point in the code.
Which of the following are legal definitions with initializations? (Consider each line to be in a different scope so there is no multiple definition of identifiers.) a) int count = 0, limit = 19; b) int count(0), limit(19); c) int count = 0, limit(19); d) int limit = 19; e) int namespace(0);
e) int namespace(0);
A switch statement must have a) a default case b) more than one non-default case c) a break statement d) all of the above e) none of the above
e) none of the above
Which of the following names might give the human reader some hint about the data that is stored in them? a) aa, bb, cc b) spd, dst, tm c) v1, v2, v3 d) leg1, leg2, leg3 e) principal, interest, payment
e) principal, interest, payment
The sqrt function... a) is provided in the library header b) returns the square of the argument c) returns the nth root of the argument d) the argument type is int e) the return type is double.
e) the return type is double.
An assignment of the value of a conditional expression to a variable (x =y?z:w;) can never be replaced by a) a switch statement with assignment statements for its case statements b) one or more ifs with else clauses and assignment statements for its true and false clauses. c) one or more nested while loops with assignments for the bodies of the loops. d) one or more ifs without any else clauses and assignment statements for its yes_statement(s). e) these are all correct and may be used to replace the variable statement given.
e) these are all correct and may be used to replace the variable statement given.