Question: QUESTION 1 The definition of a variable outside any function is called local variable definition global variable definition global function definition global function header QUESTION
QUESTION 1
The definition of a variable outside any function is called
|
| local variable definition | |
|
| global variable definition | |
|
| global function definition | |
|
| global function header |
QUESTION 2
A void function can have
|
| exactly one argument | |
|
| no more than 3 arguments | |
|
| no arguments | |
|
| as many arguments as the programmer wishes |
QUESTION 3
Which of the following statements about the definition and declaration of functions is incorrect?
(Note. Function definition includes the body of the function also called function block)
|
| A function header is exactly the same as function prototype except for the semicolon | |
|
| Function definition is exactly the same as function prototype | |
|
| A function definition is a function header followed by the function block | |
|
| Function declaration is exactly the same as function prototype |
QUESTION 4
Where can you NOT declare a variable in a C++ program?
|
| Within the argument list of a function call | |
|
| Within the parameter list of a function definition | |
|
| Within the block of a void function | |
|
| Within a block nested within another block
|
QUESTION 5
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, Ill 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;
}
|
| d is a local variable in the main function | |
|
| value is a local variable in the main function | |
|
| num is a global constant | |
|
| NUM is a global variable
|
QUESTION 6
What do the calls to exit(...) do? When exit(0) and exit(1) are called, what receives these values and what is done with them?
|
| the exit() function is obsolete. There is no longer any such function in the C++ libraries | |
|
| the exit() function stops the program. The value is passed to the operating system which uses it for an error code | |
|
| the exit() function stops the program. The value is discarded. | |
|
| 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. |
QUESTION 7
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;
}
|
| The variable i is undefined in this scope, so this should not compile | |
|
| 9 | |
|
| 10 | |
|
| 0
|
QUESTION 8
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 correct invocations for the function pow?
|
| power = pow(base, exponent);
| |
|
| base-1 = pow(exponent, power); | |
|
| pow(power, base, exponent); | |
|
| pow(base, exponent) = power; |
QUESTION 9
Which statement is incorrect?
|
| A variable declared outside any function is said to be a global variable | |
|
| It is legal to replace the prototype double totalCost(int numberParam, double priceParam); with the more terse, alternate form double totalCost(int, double); | |
|
| Extensive use of global variables is NOT a satisfactory replacement for the difficulties of parameter passing with functions | |
|
| In C++ Boolean value are represented only with the int values 0 for false and 1 for true |
QUESTION 10
Which statement is incorrect?
|
| Consider two blocks, one within another. If an identifier is declared as a variable in the innermost of these two blocks, one can access this variable from the outer block | |
|
| A local variable is created in the execution stack | |
|
| Consider two blocks, one within another. C++ allows an identifier to be declared as a variable in each of these blocks | |
|
| A variable declared within a function block is said to be local to the function
|
QUESTION 11
A semicolon does not (usually) go after these with the exception of
|
| a function header to make it a function declaration | |
|
| if (condition) | |
|
| int main() | |
|
| while (condition) |
QUESTION 12
Which of the following code fragments gives a random 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
|
| 3.0*rand() + 2 | |
|
| rand()/static_cast (RAND_MAX)*2 +3 | |
|
| (RAND_MAX - rand())/static_cast | |
|
| 3.0*(RAND_MAX-rand())/RAND_MAX + 2 |
QUESTION 13
A call to a C++ function is
|
| The name of the function followed by empty parentheses | |
|
| The name of the function followed by a number of arguments not greater than the number of parameters in the definition | |
|
| The name of the function followed by any number of arguments, regardless of the number of parameters in the definition | |
|
| The name of the function followed by exactly the number of arguments as there are parameters in the definition |
QUESTION 14
In C++ array indices, that is subscript values, must be
|
| Less than or equal to the declared size of the array | |
|
| positive | |
|
| None is correct | |
|
| Non-negative, integer
|
QUESTION 15
Which statement is incorrect?
|
| If we want to find the median of 100 scores, we need 100 separate variables to hold the data | |
|
| The programmer should always use a defined constant in an array declaration | |
|
| With arrays, indices start with the number 0 | |
|
| An array behaves like a list of variables each of which is of the same type and for which there is a uniform, convenient naming convention that can be declared in a single line of code. |
QUESTION 16
Which statement is incorrect?
|
| To call a function with an array parameter, write the array argument as the array name followed by empty square brackets, as in f(a[], 7); (The first argument is an array a, the second is the size.)
| |
|
| Given the two C++ array declarations: int a[10], b[10]; You can NOT assign b to a: a = b;
| |
|
| Consider the array declaration, int x[20];. There is no memory allocated for x[20] | |
|
| Arrays in C++ can store one type of data per array |
QUESTION 17
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;
|
| ecko followed by a character from an out of bounds access | |
|
| kceg followed by a character from an out of bounds access | |
|
| okceg | |
|
| gecko |
QUESTION 18
Are the following array initializations INcorrect?
|
| const int SIZE =4; int x[SIZE];
| |
|
| int x[4] = {8, 7, 6, 5, 4};
| |
|
| int x[] = {8, 7, 6, 5, 4};
| |
|
| int x[4] = {8, 7, 6}; |
QUESTION 19
Which statement is incorrect?
|
| Indexed variables for an array are stored wherever the computer finds memory for the first indexed variable, then the next one is stored next to the first if there is space, and someplace else if not.
| |
|
| If you need an array with more than one index, you can use a multidimensional array, which is actually an array of arrays | |
|
| C++ arrays do not check for out-of-range index values | |
|
| A for-loop is a convenient way to step through an array
|
QUESTION 20
Given the array declaration, int a[20]; The first element is written as:
|
| a[20] | |
|
| a | |
|
| a[1] | |
|
| a[0 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
