WorksheetsABD8 (C++)
Total questions: 20
Worksheet time: 24mins
True or False. A void function cannot have a return value.
True
False
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;
55
25
16
no output--this is an infinite loop
XX functionName (parameter1, parameter2,...) { // function body } what does XX represents?
function type
function call
return type
function
function is executed when it is
defined
called
declared
prototyped
A function that is not void needs to have a _____ _______
variable calculation
printing statement
Return statement
cout statement
What is the index of the first element in a C++ array?
1
-1
0
Depends on the array size
What is the output of the following code in C++?
int arr[4] = {10, 20, 30, 40};
cout << arr[1] + arr[3];
30
40
50
60
What is the output of the included code?
321
123
32
111
No output
______allows the programmer to terminate the loop and
exit
break
terminate
none of the choice mentioned
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 ++ ;
}
Select all of the statements properly decrements an int variable by one?
variable = variable - 1;
variable -= 1;
variable - -;
variable - variable;
variable - 1;
_______ causes the control to pass on to the beginning of the block/loop.
break
goto
exit
continue
Select all of the statements properly increments an int variable by one?
variable++;
variable += 1;
variable + 1;
variable = variable * variable;
How many times is "yoyo" printed when the following code executes?
for(int i = 1; i < 7; i += 2)
cout<<"yoyo";
0
2
3
4
infinitely many times
What is the output of the above program?
0 1 2 3 4
0 1 2 3
0 1 2 4
0 1 2
If you want a user to enter exactly 20 values, which loop would be the best to use?
while
switch
do-while
for
What output is produced by the following segment of code:
for(int fun = 20; fun > 1; fun -=3)
cout << fun << " ";
20 17 14 11 8 5 2 -1
20 17 14 11 8 5 2
17 14 11 8 5 2 -1
20 17 14 11 8 5
Infinite Loop
What does the following C++ program fragment do?
while (count < 10)
count++;
cout << "Hello";
prints nothing
prints "Hello" once
prints "Hello" 9 times
prints "Hello" forever
What output is produced by the following segment of code:
int start = 5;
int end = 20;
for(; start <= end; start +=2)
cout << start << " ";
5 7 9 11 13 15 17 19 21
7 9 11 13 15 17 19 20
7 9 11 13 15 17 19 21
5 7 9 11 13 15 17 19
Infinite Loop
What is the output of the above program?
0 1 2 3 4
0 1 2 3
0 1 2
0 1
