What is the purpose of a "for loop" in C++?

C++ For Loop Quiz

Quiz
•
Computers
•
University
•
Hard
Harshita Kanojia
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
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 Quizizz
10 questions
C Programming Basics - 002

Quiz
•
University
12 questions
BE4 UPS 3 D2T10

Quiz
•
University
9 questions
FST Class 2023- Quiz 5

Quiz
•
University
10 questions
CSC126_Chapter4_Part1

Quiz
•
University
5 questions
For Loop in C++

Quiz
•
11th Grade - University
14 questions
Understanding Loops in C Language

Quiz
•
University
10 questions
JAVA operators

Quiz
•
University
15 questions
BASIC C PROGRAMMING QUIZ

Quiz
•
University
Popular Resources on Quizizz
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