wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Session 5 Array fundamentals

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

How do we declare array of 10 integers?

a)

int arr;

b)

string arr[10];

c)

int arr[9];

d)

int arr[10];

2.

Which index that array in c++ start from?

a)

1

b)

0

c)

-1

3.

How can you access the 5th element of an array named arr?

a)

arr[4];

b)

arr[5]

c)

arr(5);

d)

arr{4}

4.

What happens if you try to access an index outside the array bounds?

a)

Compilation error always

b)

Undefined behavior

c)

The program automatically resizes the array

d)

Nothing happens, safe access

5.

C++ allows dynamically changing the size of a fixed-size array once declared.

a)

True

b)

False

6.

The size of an array must be a constant expression in C++.

a)

True

b)

False

7.

Arrays in C++ can store elements of different data types?

a)

True

b)

False

8.

#include <iostream>

using namespace std;

int main() {

int arr[5] = {10, 20, 30, 40, 50};

int sum = 0;

for(int i = 0; i < 4; i++) {

sum += arr[i];

}

cout << "Sum = " << sum << endl;

return 0;

}

a)

sum=100

b)

sum=150

c)

sum=70

d)

sum=0

9.

int arr[4] = {3, 6, 9, 12};

int total = 0;

for(int i = 0; i < 4; i++) {

total += arr[i];

cout << "Step " << i+1 << ": total = " << total << endl;

}

=> what will be the total value after 2 iterations (cycles)

a)

3

b)

6

c)

9

d)

18

10.

#include <iostream>

using namespace std;

int main() {

int numbers[3] = {5, 10, 15};

cout << numbers[1] << endl;

return 0;

}

a)

output= 5

b)

output= 10

c)

output= 15

d)

output= 5+10