do while , for, Arrays

do while , for, Arrays

University

16 Qs

quiz-placeholder

Similar activities

DSA (QUIZ 6) Hashing, Graphs, Advanced Graph Algorithms, and DP

DSA (QUIZ 6) Hashing, Graphs, Advanced Graph Algorithms, and DP

University

20 Qs

PHP Programming Quiz 2

PHP Programming Quiz 2

University

14 Qs

Review loops

Review loops

8th Grade - University

12 Qs

Computer Programming I Finals

Computer Programming I Finals

University

11 Qs

AR - 1.5 - Looping Shuffles

AR - 1.5 - Looping Shuffles

8th Grade - University

17 Qs

แข่งขันcodingม.ปลาย

แข่งขันcodingม.ปลาย

12th Grade - University

15 Qs

Introduction to C# Programming

Introduction to C# Programming

10th Grade - University

20 Qs

PPL 223 - (QUIZ 3) Data Types and Structures

PPL 223 - (QUIZ 3) Data Types and Structures

University

15 Qs

do while , for, Arrays

do while , for, Arrays

Assessment

Quiz

Information Technology (IT)

University

Medium

Created by

Fatma Metwally

Used 1+ times

FREE Resource

16 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which loop type will always execute at least once, regardless of the condition?

do-while loop

while loop

for loop

foreach loop

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

If a for loop has a condition i < 10, but inside the loop, we have a statement i += 3;, how many times will it run starting from i = 0?

6

4

3

5

Answer explanation

Starting from i = 0, the loop increments i by 3 each time: 0, 3, 6, 9. After that, i becomes 12, which is not less than 10. Thus, the loop runs 4 times before exiting.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following correctly initializes a 2D array in C++ with all zeros?

  • int arr[3][3] = {};

  • int arr[3][3] = {0};

  • int arr[3][3] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };

  • All of the above

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which loop is most appropriate for iterating over elements when the number of iterations is known in advance?

do-while loop

while loop

for loop

foreach loop

5.

MULTIPLE SELECT QUESTION

45 sec • 1 pt

Which statement about arrays in C++ is true?

  • Array indices start at 1.

Arrays in C++ can store elements of different types.

Arrays in C++ store elements of the same type.

  • Array size must be specified at the time of declaration.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In a 2D array declared as int matrix[3][3];, how do you access the element at the first row and second column?

matrix[0][1]

matrix[0][2]

matrix[2][1]

matrix[1][0]

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What will be the output of the following code?

  • 100

20

90

40

Answer explanation

The loop accesses elements at indices 1 and 3 (arr[1] = 20, arr[3] = 40), so sum = 20 + 40 = 60.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?