Search Header Logo

C++ For Loop Quiz

Authored by Harshita Kanojia

Computers

University

Used 3+ times

C++ For Loop Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

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

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?