AlgoMaster Logo

Introduction to C++ - Quiz

Last Updated: December 6, 2025

Introduction to C++ Quiz

30 quizzes

1
Multiple Choice

Which statement best describes C++?

2
Multiple Choice

Who created C++ and where was it first developed?

3
Multiple Choice

Which C++ feature is MOST associated with code reuse and modular design?

4
Multiple Choice

Which standard introduced the first official ISO C++ standard?

5
Multiple Choice

Compared to C, which capability is a key addition in C++?

6
Multiple Choice

Which choice is the BEST reason to use an IDE when learning C++?

7
Multiple Choice

In a minimal C++ program, what is the purpose of the function named main?

8
Multiple Choice

Which phase of the build pipeline resolves external function calls into final addresses?

9
Multiple Choice

Which real-world application commonly uses C++ for its performance and low-level control?

10
Multiple Choice

Which modern C++ feature helps manage memory automatically and safely?

11
Code Completion

Include the correct header to use std::cout

cpp
1
#include <>

Click an option to fill the blank:

12
Code Completion

Complete the line to declare main with the correct return type

cpp
1
main() { return 0; }

Click an option to fill the blank:

13
Code Completion

Use the C++ compiler to build hello.cpp into an executable named hello

cpp
1
g++ hello.cpp hello

Click an option to fill the blank:

14
Output Prediction

What is the output of this code?

1#include <iostream>
2using namespace std;
3
4class Animal {
5public:
6    void speak() {
7        cout << "Animal speaks" << endl;
8    }
9};
10
11class Dog : public Animal {
12public:
13    void speak() {
14        cout << "Dog barks" << endl;
15    }
16};
17
18int main() {
19    Dog d;
20    d.speak();
21    return 0;
22}
15
Output Prediction

What does this program print?

1#include <iostream>
2
3int main() {
4    int *p = new int(42);
5    std::cout << *p << std::endl;
6    delete p;
7    return 0;
8}
16
Output Prediction

What is the output of this C++ vs C style example?

1#include <iostream>
2
3void greet_c() {
4    std::cout << "Hello from C style" << std::endl;
5}
6
7class Greeter {
8public:
9    void greet_cpp() {
10        std::cout << "Hello from C++ style" << std::endl;
11    }
12};
13
14int main() {
15    greet_c();
16    Greeter g;
17    g.greet_cpp();
18    return 0;
19}
17
Output Prediction

What is the output after compiling with optimizations disabled?

1#include <iostream>
2
3int add(int a, int b) {
4    return a + b;
5}
6
7int main() {
8    int x = 3;
9    int y = 4;
10    std::cout << add(x, y) << std::endl;
11    return 0;
12}
18
Output Prediction

What does this program print about the compilation process?

1#include <iostream>
2
3void step(const char* msg) {
4    std::cout << msg << std::endl;
5}
6
7int main() {
8    step("1. Preprocessing");
9    step("2. Compilation");
10    step("3. Assembly");
11    step("4. Linking");
12    return 0;
13}
19
Bug Spotting

Find the bug related to memory management in this C-style code

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

cpp
1
#include <cstdlib>
2
 
3
int main() {
4
    int *data = (int*)std::malloc(5 * sizeof(int));
5
    for (int i = 0; i < 5; ++i) {
6
        data[i] = i;
7
    }
8
    // process data
9
    return 0;
10
}
20
Bug Spotting

Find the bug in this first C++ program using std::cout

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

cpp
1
#include <iostream>
2
 
3
int main() {
4
    cout << "Hello" << std::endl;
5
    return 0;
6
}
21
Hotspot Selection

Click the line that causes a potential leak when an early return happens

Click on the line to select.

cpp
1
void init_system(bool fail) {
2
    int* buffer = new int[100];
3
    // initialize buffer
4
    if (fail) return; // early exit
5
    delete[] buffer;
6
}
22
Hotspot Selection

Click the line where the C++ program actually starts executing

Click on the line to select.

cpp
1
#include <iostream>
2
 
3
void helper() {
4
    std::cout << "Helper" << std::endl;
5
}
6
 
7
int main() {
8
    helper();
9
    std::cout << "Main" << std::endl;
10
    return 0;
11
}
23
Fill in the Blanks

Complete the Hello World program

cpp
1
<iostream>
2
3
int main() {
4
std:: << "Hello, World!" << std::;
5
return 0;
6
}

Click an option to fill blank 1:

24
Fill in the Blanks

Fill in the C++ class and object usage

cpp
1
class {
2
public:
3
void speak() {
4
std::cout << "Hi" << std::endl;
5
}
6
};
7
8
int main() {
9
;
10
.speak();
11
return 0;
12
}

Click an option to fill blank 1:

25
Fill in the Blanks

Complete the use of std::vector from the STL

cpp
1
#include <iostream>
2
#include <>
3
4
int main() {
5
std::<int> v = {1, 2, 3};
6
for ( x : v) {
7
std::cout << x << std::endl;
8
}
9
return 0;
10
}

Click an option to fill blank 1:

26
Fill in the Blanks

Fill in the RAII-style smart pointer example

cpp
1
#include <iostream>
2
#include <memory>
3
4
int main() {
5
std::<int> p = std::<int>();
6
std::cout << *p << std::endl;
7
return 0;
8
}

Click an option to fill blank 1:

27
Matching

Match the compilation stage with its main responsibility

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

28
Matching

Match each tool with its typical role in a C++ environment

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 compile and run a simple C++ program from the command line

Drag and drop to reorder, or use the arrows.

30
Sequencing

Order these actions when setting up a C++ environment with VS Code and GCC

Drag and drop to reorder, or use the arrows.

Premium Content

Subscribe to unlock full access to this content and more premium articles.