What will be the output of the following code?
int i = 0;
while (i < 3)
{
cout << "Number: " << i << endl;
i++;
}
C++ Programming Quiz
Quiz
•
Computers
•
12th Grade
•
Medium
Wasiha Tasneem
Used 14+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What will be the output of the following code?
int i = 0;
while (i < 3)
{
cout << "Number: " << i << endl;
i++;
}
Number: 1
Number: 2
Number: 3
Number: 0
Number: 1
Number: 2
Number: 0
Number: 1
Number: 2
Number: 3
None of the above
2.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What will be the output of the following code using `switch case`?
char ch = 'b';
switch(ch)
{
case 'a': cout << "Apple";
case 'b': cout << "Banana";
case 'c': cout << "Cherry";
default: cout << "None";break;
}
Apple
Banana
Cherry
None
Banana
Cherry
None
Cherry
None
None
3.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What is the output of this program with a `while` loop?
int num = 6;
while (num >= 1)
{
cout << num << " ";
--num ; }
6 5 4 3 2 1
1 2 3 4 5 6
6 5 4 3 2
Infinite loop
4.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What will be the output of this C++ code using a `do while` loop?
int num = 1;
do
{
cout << num << " ";
num++;
} while (num <= 5);
1 2 3 4 5
1 2 3 4
0 1 2 3 4
None of the above
5.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What will the following code output?
int i = 1, sum = 0;
for (; i <= 5; i++)
{
sum += i;
} cout << sum;
15
10
5
None of the above
6.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What will be the output of the following code with a `continue` statement?
for (int i = 1; i <= 5; i++)
{
if (i == 3)
continue;
cout << i << " ";
}
`1 2 3 4 5`
`1 2 4 5`
`1 2 4`
None of the above
7.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What will be the output of this program with nested loops?
for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= 3; j++)
{
cout << i << j << " ";
}
cout << endl;
}
11 12 13
21 22 23
31 32 33
11 21 31
12 22 32
13 23 33
11 22 33
11 22 33
11 22 33
1 2 3
1 2 3
1 2 3
13 questions
C++ Loops
Quiz
•
9th - 12th Grade
12 questions
Arrays Intro
Quiz
•
9th - 12th Grade
10 questions
Introduction to C++ 2024/25
Quiz
•
12th Grade
15 questions
Latihan Pemrograman
Quiz
•
12th Grade
10 questions
Functions in C++
Quiz
•
9th - 12th Grade
11 questions
computer 12
Quiz
•
12th Grade
10 questions
Bài tập trắc nghiệm C++
Quiz
•
3rd - 12th Grade
10 questions
Programming with C++
Quiz
•
9th - 12th Grade
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade
17 questions
Parts of Speech
Quiz
•
7th - 12th Grade
20 questions
Chapter 3 - Making a Good Impression
Quiz
•
9th - 12th Grade
20 questions
Inequalities Graphing
Quiz
•
9th - 12th Grade
10 questions
Identifying equations
Quiz
•
KG - University