Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

ABD8 (C++)

Total questions: 20

Worksheet time: 24mins

Name
Class
Date
1.

True or False. A void function cannot have a return value.

a)

True

b)

False

2.

what is the output of the following code fragment? (All variables are of type int.)

sum = 0;

num = 9;

while (num != 0)

{

sum = sum + num;

num = num - 2;

}

cout << sum << endl;

a)

55

b)

25

c)

16

d)

no output--this is an infinite loop

3.

XX functionName (parameter1, parameter2,...) { // function body } what does XX represents?

a)

function type

b)

function call

c)

return type

d)

function

4.

function is executed when it is

a)

defined

b)

called

c)

declared

d)

prototyped

5.

A function that is not void needs to have a _____ _______

a)

variable calculation

b)

printing statement

c)

Return statement

d)

cout statement

6.

What is the index of the first element in a C++ array?

a)

1

b)

-1

c)

0

d)

Depends on the array size

7.

What is the output of the following code in C++?

int arr[4] = {10, 20, 30, 40};

cout << arr[1] + arr[3];

a)

30

b)

40

c)

50

d)

60

8.

What is the output of the included code?

a)

321

b)

123

c)

32

d)

111

e)

No output

9.

______allows the programmer to terminate the loop and 

a)

exit

b)

break  

c)

terminate

d)

none of the choice mentioned

10.

Fill in the blank with the right symbol to make this code print I'm a coder

3 times


int loop = 0;


while(loop (a)   3){

cout<<“I'm a coder”<<endl;


loop ++ ;

}

11.

Select all of the statements properly decrements an int variable by one?

a)

variable = variable - 1;

b)

variable -= 1;

c)

variable - -;

d)

variable - variable;

e)

variable - 1;

12.

_______ causes the control to pass on to the beginning of the block/loop.

a)

break

b)

goto

c)

exit

d)

continue

13.

Select all of the statements properly increments an int variable by one?

a)

variable++;

b)

variable += 1;

c)

variable + 1;

d)

variable = variable * variable;

14.

How many times is "yoyo" printed when the following code executes?

for(int i = 1; i < 7; i += 2)

cout<<"yoyo";

a)

0

b)

2

c)

3

d)

4

e)

infinitely many times

15.

What is the output of the above program?

a)

0 1 2 3 4

b)

0 1 2 3

c)

0 1 2 4

d)

0 1 2

16.

If you want a user to enter exactly 20 values, which loop would be the best to use?

a)

while

b)

switch

c)

do-while

d)

for

17.

What output is produced by the following segment of code:


for(int fun = 20; fun > 1; fun -=3)

cout << fun << " ";

a)

20 17 14 11 8 5 2 -1

b)

20 17 14 11 8 5 2

c)

17 14 11 8 5 2 -1

d)

20 17 14 11 8 5

e)

Infinite Loop

18.

What does the following C++ program fragment do?

while (count < 10)

count++;

cout << "Hello";

a)

prints nothing

b)

prints "Hello" once

c)

prints "Hello" 9 times

d)

prints "Hello" forever

19.

What output is produced by the following segment of code:


int start = 5;

int end = 20;

for(; start <= end; start +=2)

cout << start << " ";

a)

5 7 9 11 13 15 17 19 21

b)

7 9 11 13 15 17 19 20

c)

7 9 11 13 15 17 19 21

d)

5 7 9 11 13 15 17 19

e)

Infinite Loop

20.

What is the output of the above program?

a)

0 1 2 3 4

b)

0 1 2 3

c)

0 1 2

d)

0 1