wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Functions

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

Select the correction function prototype from the following options. Select 2 correct answers.

a)

void first();

b)

void first()

c)

void myFunction():

d)

void myFunction();

2.

Fill in the blank: Function prototypes are also known as ____

a)

function declarations

b)

function assignments

c)

function operations

d)

function definitions

3.

Select a correct function call.

a)

myValue(int 7);

b)

myValue(7);

c)

myValue(double, 7000);

d)

myValue (4.2)

4.

Select the correct syntax for a function header that contains a parameter list.

a)

void showTotal (int num1, int num2, num3)

b)

void showTotal (int num1, num2, num3)

c)

void showTotal (int num1, int num2, int num3)

d)

void showTotal (num1, num2, num3)

5.

What type of statement will force the function to end immediately?

a)

end;

b)

terminate;

c)

quit;

d)

return;

6.

Fill in the blank:

Data can be returned from a function, back to the statement that called it, which is known as ____.

a)

data-passing function

b)

value-returning function

c)

value-assignment function

d)

data-populating function

7.

Which of the following function will return a value?

a)

int sum (int val1, int val2)

{

return val1+val2;

}

b)

void sum (int val1, int val2)

{

return sum;

}

c)

void sum (int val1, int val2)

{

return val1+val2;

}

d)

int sum (val1, val2)

{

return sum;

}

8.

What value is returned in the following code snippet?

bool isValid(int number)

{

bool status;

if (number >= 1 && number <= 100)

status = true;

else

status = false;

return status;

}

a)

number between 1 to 100

b)

valid or invalid

c)

"status"

d)

true or false

9.

What is the lifetime of the local variable?

a)

as long as the computer is on

b)

while the function is executing

c)

forever

d)

until the function is called

10.

By default, global variable is initialized with what value?

a)

255

b)

1

c)

0

d)

not initialized to any value by default

11.

Fill in the blank:

A named constant that is available to every function in a program is known as ____.

a)

global variable

b)

local variable

c)

global constant

d)

local constant

12.

Select the correct statement.

a)

two local variables with the same name can exist in the same function.

b)

a parameter variable and a local variable can have the same name in the same function.

c)

a local variable variable can have the same name as a global variable.

d)

the name of the local or parameter variable can never be the same as the name of the global constant.

13.

All static local variables are initialized to what by default?

a)

0

b)

1

c)

256

d)

255

14.

Identify the default argument in prototype:

void showArea(double = 20.0, double = 10.0);

a)

20.0 and 10.0

b)

double and double

c)

showArea

d)

there is no default argument

15.

Select the correct prototype

a)

void calcPay(double hours = 40.0, int empNum, double payRate);

b)

void calcPay(int empNum, double hours = 40.0, double payRate);

c)

void calcPay(int empNum, double payRate, double hours = 40.0);

d)

void calcPay(int empNum = 1, double payRate = 22, double hours);

16.

Which of the following option represents a reference variable myVar?

a)

void doubleNum (int myVar);

b)

void doubleNum (int %myVar)

c)

void doubleNum (int &myVar)

d)

void doubleNum (int, myVar)

17.

Fill in the blank:

When you assign the same name to multiple functions, but use different parameter lists, this is known as ______.

a)

Overloading functions

b)

Replicating functions

c)

Passing functions

d)

Alternating functions

18.

What is the signature of the function header:

double square(double number)?

a)

square (double number)

b)

double (double number)

c)

square (double)

d)

square (number)

19.

What type of function causes a program to terminate, regardless of which function or control mechanism is executing?

a)

terminate()

b)

end()

c)

quit()

d)

exit()

20.

What type of program tests a function by simply calling it and passes test data if the function accepts arguments?

a)

stub

b)

driver

c)

tester

d)

pass