AlgoMaster Logo

Basic Syntax - Quiz

Last Updated: January 3, 2026

Basic Syntax Quiz

30 quizzes

1
Multiple Choice

Which declaration correctly defines a local integer variable in C++?

2
Multiple Choice

What is the main benefit of using a named const instead of a literal like 100 scattered in code?

3
Multiple Choice

Which operator has the highest precedence in C++?

4
Multiple Choice

Which line correctly reads an int value from standard input?

5
Multiple Choice

Which C++ comment style is best for a short note at the end of a single line of code?

6
Multiple Choice

What happens when you convert a double to int using static_cast<int>(value)?

7
Multiple Choice

Which is a valid way to declare a constant double for Pi?

8
Multiple Choice

Which literal is a character literal?

9
Multiple Choice

Which expression uses a logical operator to check two conditions?

10
Multiple Choice

Which statement about std::cout and std::cin is correct?

11
Code Completion

Declare and initialize a boolean variable using a literal

cpp
1
bool isReady = ;

Click an option to fill the blank:

12
Code Completion

Cast an int to double using static_cast

cpp
1
double d = static_cast<double>();

Click an option to fill the blank:

13
Code Completion

Declare a constant integer representing a buffer size

cpp
1
const int = 1024;

Click an option to fill the blank:

14
Output Prediction

What is the output of this code?

1#include <iostream>
2int main() {
3    int a = 10;
4    int b = 3;
5    std::cout << a / b << " " << a % b << std::endl;
6    return 0;
7}
15
Output Prediction

What does this program print?

1#include <iostream>
2int main() {
3    bool flag = (5 > 3) && (2 == 4);
4    std::cout << flag << std::endl;
5    return 0;
6}
16
Output Prediction

Predict the output considering variable scope

1#include <iostream>
2int x = 5;
3void foo() {
4    int x = 10;
5    std::cout << x << " ";
6}
7int main() {
8    std::cout << x << " ";
9    foo();
10    std::cout << x << std::endl;
11    return 0;
12}
17
Output Prediction

What is the output regarding type casting?

1#include <iostream>
2int main() {
3    double price = 9.99;
4    int whole = static_cast<int>(price);
5    std::cout << price << " " << whole << std::endl;
6    return 0;
7}
18
Output Prediction

What does this I/O code print if the user enters: 25<Enter>John<Enter>?

1#include <iostream>
2#include <string>
3int main() {
4    int age;
5    std::string name;
6    std::cin >> age;
7    std::cin >> name;
8    std::cout << name << " is " << age << std::endl;
9    return 0;
10}
19
Bug Spotting

Find the bug related to constants and assignment

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

cpp
1
#include <iostream>
2
int main() {
3
    const int MAX_COUNT = 10;
4
    int count = 0;
5
    while (count < MAX_COUNT) {
6
        std::cout << count << " ";
7
        if (count == 5) {
8
            MAX_COUNT = 3;
9
        }
10
        ++count;
11
    }
12
    return 0;
13
}
20
Bug Spotting

Identify the bug involving uninitialized variables and I/O

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

cpp
1
#include <iostream>
2
int main() {
3
    int value;
4
    if (value > 0) {
5
        std::cout << "Positive" << std::endl;
6
    } else {
7
        std::cout << "Non-positive" << std::endl;
8
    }
9
    return 0;
10
}
21
Hotspot Selection

Click the line where an integer literal is used to initialize a variable

Click on the line to select.

cpp
1
#include <iostream>
2
int main() {
3
    int x;
4
    x = 5;
5
    std::cout << x << std::endl;
6
    return 0;
7
}
22
Hotspot Selection

Click the line that performs an explicit type cast

Click on the line to select.

cpp
1
#include <iostream>
2
int main() {
3
    int total = 7;
4
    int count = 2;
5
    double avg1 = total / count;
6
    double avg2 = static_cast<double>(total) / count;
7
    std::cout << avg2 << std::endl;
8
    return 0;
9
}
23
Fill in the Blanks

Complete the code to declare and initialize variables with appropriate types and literals

cpp
1
#include <iostream>
2
int main() {
3
age = ;
4
pi = ;
5
std::cout << age << " " << pi << std::endl;
6
return 0;
7
}

Click an option to fill blank 1:

24
Fill in the Blanks

Complete the code to read a full line of text and an integer

cpp
1
#include <iostream>
2
#include <string>
3
int main() {
4
std::string name;
5
int age;
6
std::getline(, );
7
>> age;
8
std::cout << name << " " << age << std::endl;
9
return 0;
10
}

Click an option to fill blank 1:

25
Fill in the Blanks

Fill in the blanks to define and use a constant and a relational operator

cpp
1
#include <iostream>
2
int main() {
3
const int LIMIT = ;
4
int value = 12;
5
if (value LIMIT) {
6
std::cout << "Too high" << std::endl;
7
}
8
return 0;
9
}

Click an option to fill blank 1:

26
Fill in the Blanks

Complete the code to demonstrate explicit casting in an arithmetic expression

cpp
1
#include <iostream>
2
int main() {
3
int sum = 7;
4
int count = 2;
5
double avg = static_cast<>() / count;
6
std::cout << avg << std::endl;
7
return 0;
8
}

Click an option to fill blank 1:

27
Matching

Match each literal type with an example

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

28
Matching

Match each stream-related term with its description

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 read an integer from input and print its double

Drag and drop to reorder, or use the arrows.

30
Sequencing

Order the steps to safely cast a double to int and print both values

Drag and drop to reorder, or use the arrows.