Anda di halaman 1dari 28

Exam Practice Tests

Functions
What is the output of the following program?



Answer


5


2


7


"getValue(x)"

A function ________ eliminates the need to place a function definition before all calls to
the function.
Answer


header


prototype


argument


parameter


None of these

________ functions may have the same name, as long as their parameter lists are
different.
Answer


Only two


Two or more


Zero


Un-prototyped


None of these

A(n) ________ argument is passed to a parameter when the actual argument is left out
of the function call.
Answer


false


true


null


default


None of these
This is a dummy function that is called instead of the actual function it represents.
Answer


main function


stub


driver


overloaded function
Here is the header for a function named computeValue:



Which of the following is a valid call to the function?
Answer


computeValue(10)


computeValue(10);


void computeValue(10);


void computeValue(int x);

What is the output of the following program?


Answer


2
2


4
2


2
4


4
4

EXIT_FAILURE and ________ are named constants that may be used to indicate
success or failure when the exit( ) function is called.
Answer


EXIT_TERMINATE


EXIT_SUCCESS


EXIT_OK


RETURN_OK


None of these
Which line in the following program contains a call to the showDub function?


Answer


4


6


10


15
Functions are ideal for use in menu-driven programs. When a user selects a menu item,
the program can ________ the appropriate function.
Answer


call


prototype


define


declare


None of these
A ________ variable is declared outside all functions.
Answer


local


global


floating-point


counter


None of these
Look at the following function prototype.



What is the data type of the funtion's parameter variable?
Answer


int


double


void


can't tell from the prototype
This statement causes a function to end.
Answer


end


terminate


return


release


None of these
If a function is called more than once in a program, the values stored in the function's
local variables do not ________ between function calls.
Answer


persist


execute


communicate


change


None of these
A function ________ contains the statements that make up the function.
Answer


definition


prototype


call


expression


parameter list
A(n) ________ is information that is passed to a function, and a(n) ________ takes the information that is passed to
the function.
Answer

function call, function header

parameter, argument

argument, parameter

prototype, header

None of these
This function causes a program to terminate, regardless of which function or control
mechanism is executing.
Answer


terminate( )


return( )


continue( )


exit( )


None of these
When used as parameters, these types of variables allow a function to access the
parameter's original argument.
Answer


reference


floating-point


counter


undeclared


None of these
What is the output of the following program?


Answer


2
0
2


2
2
2


0
0
0


2
0
0
Which line in the following program contains the prototype for the showDub function?


Answer


4


6


10


15
A function can have zero to many parameters, and it can return this many values.
Answer


zero to many


no


only one


a maximum of ten


None of these
This type of variable is defined inside a function and is not accessible outside the
function.
Answer


global


reference


local


counter


None of these
It is a good programming practice to ________ your functions by writing comments that
describe what they do.
Answer


execute


document


eliminate


prototype


None of these
Which of the following statements about global variables is true?
Answer


A global variable is accessible only to the main function.


A global variable is declared in the highest-level block in which it is used.


A global variable can have the same name as a variable that is declared locally within a
function.


If a function contains a local variable with the same name as a global variable, the global
variable's name takes precedence within the function.


All of these are true

What is the output of the following program?


Answer


2
0
2


2
2
2


0
0
0


2
0
0
The value in a(n) ________ variable persists between function calls.
Answer


dynamic


local


counter


static local
Look at the following function prototype.



How many parameter variables does this function have?
Int myfunction (double,double,double)

Answer


1


2


3


can't tell from
the prototype


These types of arguments are passed to parameters automatically if no
argument is provided in the function call.
Answer


local


default


global


relational


None of these

In a function header, you must furnish:
Answer


data type(s) of the parameters


data type of the return value


the name of function


names of parameter variables


All of these

A function is executed when it is:
Answer


defined


prototyped


declared


called


None of these
This is a collection of statements that performs a specific task.
Answer


infinite loop


variable


constant




function


None of these

This is a statement that causes a function to execute.
Answer


for loop


do-while loop


function prototype


function call


None of these

Given the following function definition


Answer


1 2 3


1 6 3


3 6 3


1 14 9


None of these


The value in this type of local variable persists between function calls.
Answer


global


internal


static


dynamic


None of these

If a function does not have a prototype, default arguments may be
specified in the function ________.
Answer


call


header


execution


return type


None of these

Which line in the following program contains the header for the showDub
function?


Answer


4


6


10


15

ook at the following function prototype.



What is the data type of the funtion's return value?
Answer


int


double


void


can't tell from the prototype


Arrays

If you leave out the size declarator in an array definition:
Answer


you must furnish an initialization list


you are not required to initialize the array elements


all array elements default to zero values


your array will contain no elements

Moving to the next question prevents changes to this answer.


Question 2

What will the following code display?

int numbers[ ] = {99, 87, 66, 55, 101 };
cout<< numbers[3]<< endl;
Answer


55


66


101


87
An array's size declarator must be a(n)________ with a value greater than
________.
Answer


number, one


number, zero


constant integer expression, zero


variable, -1


None of these
An element of a two-dimensional array is referred to by ________ followed
by ________.
Answer


the array name, the column number of element


the row subscript of the element, the column subscript of the element


a comma, a semicolon


the row subscript of element, the array name


None of these
Which of the following is a valid C++ array definition?
Answer


int array[0];


float $payments[10];


void numbers[5];


int array[10];


None of these


When writing functions that accept multi-dimensional arrays as arguments,
________ must be explicitly stated in the parameter list.
Answer


all dimensions


all but the first dimension


the size declarator of the first dimension


all element values


None of these
To access an array element, use the array name and the element's:
Answer


data type


subscript


name


value


None of these
An array can store a group of values, but the values must be:
Answer


the same data type


each of a different data type


constants


integers


None of these
The ________ is automatically appended to a character array when it is
initialized with a string constant.
Answer


array name


number of elements


value of the first element


null terminator


None of these

Subscript numbering in C++
Answer


can be set at runtime


can begin with a programmer-defined value


varies from program to program


begins with zero


None of these
To pass an array as an argument to a function, pass the ________ of the
array.
Answer


contents


size, expressed as an integer


name


value of the first element


None of these
Unlike regular variables, these can hold multiple values.
Answer


constants


named constants


arrays


floating-point variables


None of these
An array can easily be stepped through by using a:
Answer


for loop


reference variable


named constant


null value


None of these
To assign the contents of one array to another, you must use:
Answer


the assignment operator with the array names


the equality operator with the array names


a loop to assign the elements of one array to the other array


Any of these


None of these

The statement



shows an example of:
Answer


default arguments


an illegal array declaration


an illegal array initialization


implicit array sizing


None of these

Arrays may be ________ at the time they are ________.
Answer


resized, executed


re-scoped, deleted


initialized, declared


pre-compiled, typecast


None of these

What is the last legal subscript that can be used with the following array?


Answer


0


5


6


4
A(n) ________ can be used to specify the starting values of an array.
Answer


initialization list


array name


subscript


element


None of these
A two-dimensional array can be viewed as ________ and ________.
Answer


rows, columns


arguments, parameters


increments, decrements


All of these


None of these

The individual values contained in array are known as:
Answer


parts


elements


numbers


constants


None of these
What will the following code display?


Answer


99
87
66
55
101


87
66
55
101


87
66
55


Nothing. This code has an error.
A two-dimensional array of characters can contain:
Answer


strings of the same length


strings of different lengths


uninitialized elements


All of these


None of these
int bugs[1000];
Answer


1000


999


1001


cannot tell from the code
An array with no elements is:
Answer


legal in C++


illegal in C++


automatically furnished one element, with a value of zero


automatically furnished one value -- the null terminator


None of these
An array of string objects that will hold 5 names would be declared using
which statement?
Answer

string names[5];

string names(5);

string names5;

String[5] names;


None of these will work.

What will the following code do?


Answer


Each element in the array is initialized to 0.0.


Each element in the array, except the first, is initialized to 0.0.


Each element in the array, except the first and the last, is initialized to 0.0.


An error will occur when the code runs.


Which of the following is a valid C++ array definition?
Answer


int scores[0];


float $payments[10];


int readings[4.5];


int scores [10];


None of these
The name of an array stores the ________ of the first array element.
Answer


memory address


value


element number


data type


None of these

What will the following code display?


Answer


87


0


garbage


This code will not compile.
A two-dimensional array can have elements of ________ data type(s).
Answer


one


two


four


Any of these


None of these
It is ________ to pass an argument to a function that contains an
individual array element, such as numbers[3].
Answer


illegal in C++


legal in C++


not recommended by the ANSI committee


not good programming practice


None of these
Given the following declaration, where is 77 stored in the scores array?


Answer


scores [0]


scores [1]


scores [2]


scores [4]
By using the same ________ you can build relationships between data
stored in two or more arrays.
Answer


array name


data


subscript


arguments


None of these

Pointers

Assuming ptr is a pointer variable, what will the following statement
output?

cout <<
*
ptr;
Answer


the value stored in the variable whose address is contained in ptr


the string "
*
ptr"


the address of the variable stored in ptr


the address of the variable whose address is stored in ptr


None of these
Not all arithmetic operations may be performed on pointers. For example,
you cannot ________ or ________ a pointer.
Answer


multiply, divide


add, subtract


+=, -=


increment, decrement


None of these
If a variable uses more than one byte of memory, for pointer purposes its
address is:
Answer


the address of the last byte of storage


the average of the addresses used to store the variable


the address of the first byte of storage


general delivery


None of these
A pointer variable is designed to store:
Answer


any legal C++ value


only floating-point values


a memory address


an integer


None of these
A pointer variable may be initialized with:
Answer


any non-zero integer value


any address in the computer's memory


an address less than 0


any non-zero integer value and an address less than 0 only


None of these
A pointer may be initialized with:
Answer


the address of an existing object


the value of an integer variable


the value of a floating point variable


All of these


None of these
A function may return a pointer, but the programmer must ensure that the
pointer:
Answer


still points to a valid object after the function ends


has not been assigned an address


was received as a parameter by the function


has not previously been returned by another function


None of these
Which statement displays the address of the variable num1?
Answer


cout << num1;


cout <<
*
num1;


cin >> &num1;


cout << &num1;


None of these
When you pass a pointer as an argument to a function, you must:
Answer


redeclare the pointer variable in the function call


dereference the pointer variable in the function prototype


use the #include<func_ptr.h> statement


not dereference the pointer in the function's body


None of these
The ________ and ________ operators can be used to increment or
decrement a pointer variable.
Answer


addition, subtraction


modulus, division


++, --


All of these


None of these
What will the following code output?


Answer


five memory addresses


0


3


2


1
What does the following statement do?

double
*
num2;
Answer


declares a double variable named num2


declares and initializes an pointer variable named num2


initializes a variable named
*
num2


declares a pointer variable named num2


None of these
Use the delete operator only on pointers that were:
Answer


never used


not correctly initialized


created with the new operator


dereferenced inappropriately


None of these

What will the following statement output?

cout << &num1;
Answer


the value stored in the variable called num1


the memory address of the variable called num1


the number 1


the string "&num1"


None of these

The statement int
*
ptr = new int;
Answer


results in a compiler error


assigns an integer less than 32767 to the variable named ptr


assigns an address to the variable named ptr


creates a new pointer named int


None of these
When the less than ( < ) operator is used between two pointer variables,
the expression is testing whether:
Answer


the value pointed to by the first is less than the value pointed to by the
second


the value pointed to by the first is greater than the value pointed to by the
second


the address of the first variable comes before the address of the second
variable in the computer's memory


the first variable was declared before the second variable


None of these
The ________, also known as the address operator, returns the memory
address of a variable.
Answer


asterisk ( * )


ampersand ( & )


percent sign (%)


exclamation point ( ! )


None of these
Look at the following code.



After this code executes, which of the following statements is true?
Answer


ptr will hold the address of numbers[0]


ptr will hold the address of the 2nd byte within the element numbers[0]


ptr will hold the address of numbers[1]


This code will not compile.
Look at the following statement:



This statement:
Answer


is illegal in C++


will always result in a compiler error


assigns the dereferenced pointer's value, then increments the pointer's
address


increments the dereferenced pointer's value by one, then assigns that value


None of these

Dynamic memory allocation occurs:
Answer


when a new variable is created by the compiler


when a new variable is created at runtime


when a pointer fails to dereference the right variable


when a pointer is assigned an incorrect address


None of these
These can be used as pointers.
Answer


Array names


Numeric constants


Punctuation marks


All of these


None of these
What will the following code output?

int number = 22;
int
*
var = &number;
cout << var << endl;
Answer


the address of the number variable


22


an asterisk followed by 22


an asterisk followed by the address of the number variable
When you work with a dereferenced pointer, you are actually working with:
Answer


a variable whose memory has been deallocated


a copy of the value pointed to by the pointer variable


the actual value of the variable whose address is stored in the pointer
variable


All of these


None of these
With pointer variables, you can ________ manipulate data stored in other
variables.
Answer


never


seldom


indirectly


All of these


None of these

What will the following code output?

int number = 22;
int
*
var = &number;
cout <<
*
var << endl;
Answer


the address of the number variable


22


an asterisk followed by 22


an asterisk followed by the address of the number variable
Which of the following statements deletes memory that has been
dynamically allocated for an array?
Answer


int array = delete memory;


int delete[ ];


delete [ ] array;


new array = delete;


None of these
The contents of pointer variables may be changed with mathematical
statements that perform:
Answer


all mathematical operations that are legal in C++


multiplication and division


addition and subtraction


multiplication and division and addition and subtraction


None of these
Every byte in the computer's memory is assigned a unique:
Answer


pointer


address


dynamic allocation


name


None of these
When this is placed in front of a variable name, it returns the address of
that variable.
Answer


asterisk ( * )


conditional operator


ampersand ( & )


semicolon ( ; )


None of these
Which of the following statements is not valid C++ code?
Answer


int ptr = &num1;


int ptr = int
*
num1;


float num1 = &ptr2;


All of these are valid.


All of these are invalid.
Look at the following statement.



In this statement, what does the word int mean?
Answer


The variable named
*
ptr will store an integer value.


The variable named
*
ptr will store an asterisk and an integer value.


ptr is a pointer variable that will store the address of an integer variable.


All of these


None of these
When using the new operator with an older compiler, it is good practice to:
Answer


test the pointer for the NULL address


use a preprocessor directive


clear the data from the old operator


All of these


None of these
he statement



has the same meaning as
Answer


int ptr;


*
int ptr;


int ptr
*
;


int
*
ptr;


None of these
The statement cin >>
*
num3;
Answer


stores the keyboard input into the variable num3


stores the keyboard input into the pointer called num3


is illegal in C++


stores the keyboard input into the variable pointed to by num3


None of these

Anda mungkin juga menyukai