AlgoMaster Logo

Arrays & Strings - Quiz

Last Updated: January 3, 2026

Arrays & Strings Quiz

30 quizzes

1
Multiple Choice

Which declaration correctly creates an array of 10 integers initialized to 0?

2
Multiple Choice

Given int scores[5]; as a local variable, what is the state of its elements before explicit initialization?

3
Multiple Choice

Which 2D array declaration best represents a 3x4 grid of pixels?

4
Multiple Choice

How is the null terminator represented in a C-style string?

5
Multiple Choice

Which header must be included to use std::string?

6
Multiple Choice

Which operation safely concatenates two std::string objects?

7
Multiple Choice

What is sizeof(greeting) if char greeting[] = "Hi";?

8
Multiple Choice

Which access to a 2D array matrix[3][4] is valid?

9
Multiple Choice

Given std::string s = "abc"; what does s.length() return?

10
Multiple Choice

Which is the safest way to copy a C-style string into a fixed-size buffer?

11
Code Completion

Declare a 2D array of 3 rows and 4 columns of int named matrix

cpp
1
int matrix = { {1,2,3,4}, {5,6,7,8}, {9,10,11,12} };

Click an option to fill the blank:

12
Code Completion

Initialize a C-style string with automatic null termination

cpp
1
char name[] "Alice";

Click an option to fill the blank:

13
Code Completion

Append lastName to firstName using std::string

cpp
1
std::string fullName = firstName lastName;

Click an option to fill the blank:

14
Output Prediction

What is the output of this code?

1#include <iostream>
2int main() {
3    int arr[5] = {1, 2, 3};
4    for (int i = 0; i < 5; ++i) {
5        std::cout << arr[i] << " ";
6    }
7    return 0;
8}
15
Output Prediction

What does this program print?

1#include <iostream>
2#include <string>
3int main() {
4    std::string s = "C++";
5    s += " Programming";
6    std::cout << s.size() << " " << s[0] << " " << s.back() << "\n";
7    return 0;
8}
16
Output Prediction

What is the output?

1#include <iostream>
2#include <cstring>
3int main() {
4    char src[] = "Hello";
5    char dst[10] = "Hi";
6    std::strcat(dst, src);
7    std::cout << dst << "\n";
8    return 0;
9}
17
Output Prediction

What does this program output?

1#include <iostream>
2int main() {
3    int matrix[2][3] = { {1,2,3}, {4,5,6} };
4    int sum = 0;
5    for (int r = 0; r < 2; ++r) {
6        for (int c = 0; c < 3; ++c) {
7            sum += matrix[r][c];
8        }
9    }
10    std::cout << sum << "\n";
11    return 0;
12}
18
Output Prediction

What is the output of this std::string comparison?

1#include <iostream>
2#include <string>
3int main() {
4    std::string a = "apple";
5    std::string b = "banana";
6    if (a < b) std::cout << "less";
7    else std::cout << "not less";
8    std::cout << "\n";
9    return 0;
10}
19
Bug Spotting

Find the bug related to C-style strings

Click on the line(s) that contain the bug.

cpp
1
#include <iostream>
2
#include <cstring>
3
int main() {
4
    char *name = "Alice";
5
    name[0] = 'M';
6
    std::cout << name << "\n";
7
    return 0;
8
}
20
Bug Spotting

Find the bug in this 2D array code

Click on the line(s) that contain the bug.

cpp
1
#include <iostream>
2
int main() {
3
    int rows = 2, cols = 3;
4
    int matrix[2][3] = { {1,2,3}, {4,5,6} };
5
    for (int r = 0; r <= rows; ++r) {
6
        for (int c = 0; c < cols; ++c) {
7
            std::cout << matrix[r][c] << " ";
8
        }
9
        std::cout << "\n";
10
    }
11
    return 0;
12
}
21
Hotspot Selection

Click the line that risks buffer overflow for a C-style string

Click on the line to select.

cpp
1
#include <iostream>
2
#include <cstring>
3
int main() {
4
    char buf[5];
5
    std::strcpy(buf, "Hello");
6
    std::cout << buf << "\n";
7
    return 0;
8
}
22
Hotspot Selection

Click the line where std::string concatenation happens

Click on the line to select.

cpp
1
#include <iostream>
2
#include <string>
3
int main() {
4
    std::string first = "C++";
5
    std::string second = "17";
6
    std::string combined = first + " " + second;
7
    std::cout << combined << "\n";
8
    return 0;
9
}
23
Fill in the Blanks

Fill blanks to read 5 integers into an array

cpp
1
#include <iostream>
2
int main() {
3
int scores[];
4
for (int i = 0; i < ; ++i) {
5
std::cin >> scores[];
6
}
7
return 0;
8
}

Click an option to fill blank 1:

24
Fill in the Blanks

Fill blanks to declare and initialize a C-style string with manual null terminator

cpp
1
char word[] = { 'O', 'K', };

Click an option to fill blank 1:

25
Fill in the Blanks

Fill blanks to use std::string append and length

cpp
1
#include <iostream>
2
#include <string>
3
int main() {
4
std::string s = "Hello";
5
s.(" World");
6
std::cout << s.() << "\n";
7
return 0;
8
}

Click an option to fill blank 1:

26
Fill in the Blanks

Fill blanks to declare and use a 2D array

cpp
1
int matrix[][] = { {1,2}, {3,4} };
2
int sum = matrix[][] + matrix[1][1];

Click an option to fill blank 1:

27
Matching

Match each string type with its description

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

28
Matching

Match each operation with the API it primarily relates to

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

29
Sequencing

Order the steps to safely read input into a C-style string buffer

Drag and drop to reorder, or use the arrows.

30
Sequencing

Order steps to iterate over a 2D array and compute the total sum

Drag and drop to reorder, or use the arrows.