
C++ For Loop Quiz

Quiz
•
Computers
•
University
•
Medium
Harshita Kanojia
Used 2+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the purpose of a "for loop" in C++?
To execute code only once
To execute code repeatedly based on a condition
To define a function
To declare a variable
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following is the correct syntax for a "for loop" in C++?
for (initialization, condition, increment/decrement) { code }
for (initialization; condition; increment/decrement) { code }
for initialization; condition; increment/decrement { code }
for { initialization; condition; increment/decrement }
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code? for (int i = 1; i <= 3; i++) { cout << i << " "; }
1 2 3
1 2 3 4
0 1 2
3 2 1
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is a prime number?
A number that is divisible by any number
A number that has only two distinct divisors: 1 and itself
A number that is always even
A number that is always odd
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will the function isPrime(7) return? bool isPrime(int num) { if (num <= 1) return false; for (int i = 2; i <= num / 2; i++) { if (num % i == 0) { return false; } } return true; }
true
false
0
Compilation error
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the following factorial program do? int factorial = 1; for (int i = 1; i <= 5; i++) { factorial *= i; } cout << factorial;
Calculates the sum of first 5 natural numbers
Calculates 5! (5 factorial)
Prints numbers from 1 to 5
Finds the largest number among 5 numbers
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How many times will the following loop execute? for (int i = 0; i < 5; i++) { cout << i; }
4 times
5 times
Infinite times
6 times
Create a free account and access millions of resources
Similar Resources on Wayground
12 questions
Chapter 2-1: Array Part 1

Quiz
•
University
9 questions
C++ Puntatori

Quiz
•
University
10 questions
Java Quiz 2 based on loop and if else

Quiz
•
University
10 questions
BCSC0006 - Quiz 1 - Arrays

Quiz
•
University
10 questions
Variables and Constants

Quiz
•
11th Grade - University
10 questions
Java MCQ Test on Control Statements

Quiz
•
University
10 questions
CIS1101-programming practice2

Quiz
•
University
15 questions
CS 2nd Semester Mid-Term

Quiz
•
10th Grade - University
Popular Resources on Wayground
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
10 questions
Ice Breaker Trivia: Food from Around the World

Quiz
•
3rd - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
20 questions
ELA Advisory Review

Quiz
•
7th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Multiplication and Division Unknowns

Quiz
•
3rd Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
11 questions
NFL Football logos

Quiz
•
KG - Professional Dev...
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
36 questions
Unit 5 Key Terms

Quiz
•
11th Grade - University
38 questions
Unit 6 Key Terms

Quiz
•
11th Grade - University
20 questions
La Hora

Quiz
•
9th Grade - University
7 questions
Cell Transport

Interactive video
•
11th Grade - University
7 questions
What Is Narrative Writing?

Interactive video
•
4th Grade - University