Bird
Raised Fist0
C++programming~10 mins

Why C++ is widely used - Test Your Understanding

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a message about C++ usage.

C++
#include <iostream>

int main() {
    std::cout << "C++ is widely used because it is [1]." << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
Aobsolete
Bslow
Cfast
Dcomplicated
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'slow' or 'obsolete' which are incorrect descriptions.
2fill in blank
medium

Complete the code to declare a variable showing C++'s feature.

C++
#include <iostream>

int main() {
    bool isObjectOriented = [1];
    std::cout << "C++ supports object-oriented programming: " << isObjectOriented << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
Atrue
B0
C"yes"
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using string "yes" instead of boolean true.
3fill in blank
hard

Fix the error in the code to correctly define a function that returns C++'s main advantage.

C++
#include <string>

std::string mainAdvantage() {
    return [1];
}
Drag options to blanks, or click blank then click option'
A42
B"performance"
Cperformance
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Returning an unquoted word causing a compile error.
4fill in blank
hard

Fill both blanks to create a map of C++ features and their descriptions.

C++
#include <iostream>
#include <map>
#include <string>

int main() {
    std::map<std::string, std::string> features = {
        {"[1]", "Supports low-level memory manipulation"},
        {"[2]", "Supports object-oriented programming"}
    };
    for (const auto& [key, value] : features) {
        std::cout << key << ": " << value << std::endl;
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
APointers
BInheritance
CTemplates
DGarbage Collection
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'Garbage Collection' which C++ does not have by default.
5fill in blank
hard

Fill all three blanks to create a function that returns a feature description based on input.

C++
#include <string>

std::string featureDescription(const std::string& feature) {
    if (feature == "[1]") {
        return "Allows code reuse and polymorphism.";
    } else if (feature == "[2]") {
        return "Enables generic programming.";
    } else if (feature == "[3]") {
        return "Provides control over system resources.";
    } else {
        return "Unknown feature.";
    }
}
Drag options to blanks, or click blank then click option'
AInheritance
BTemplates
CPointers
DGarbage Collection
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing garbage collection with pointers or templates.

Practice

(1/5)
1. Why is C++ widely used in software development?
easy
A. Because it is only used for web design
B. Because it does not support object-oriented programming
C. Because it is fast and gives control over memory
D. Because it is slower than most languages

Solution

  1. Step 1: Understand C++ performance

    C++ is known for its speed and efficiency in running programs.
  2. Step 2: Recognize memory control

    C++ allows programmers to manage memory directly, which is important for performance.
  3. Final Answer:

    Because it is fast and gives control over memory -> Option C
  4. Quick Check:

    Speed and memory control = B [OK]
Hint: Remember: speed and memory control make C++ popular [OK]
Common Mistakes:
  • Thinking C++ is only for web design
  • Believing C++ is slow
  • Ignoring memory management features
2. Which of the following is the correct way to include the standard input-output library in C++?
easy
A. #include iostream
B. #include <iostream>
C. import iostream;
D. #include <stdio>

Solution

  1. Step 1: Recall C++ syntax for including libraries

    C++ uses #include with angle brackets for standard libraries.
  2. Step 2: Identify correct syntax

    #include <iostream> is the correct way to include the input-output stream library.
  3. Final Answer:

    #include <iostream> -> Option B
  4. Quick Check:

    #include <iostream> = D [OK]
Hint: Use #include with angle brackets for standard C++ libraries [OK]
Common Mistakes:
  • Using #include <stdio> instead of <iostream>
  • Writing import instead of #include
  • Missing angle brackets around library name
3. What will be the output of this C++ code?
int main() {
    int a = 5;
    int b = 10;
    int c = a + b;
    std::cout << c << std::endl;
    return 0;
}
medium
A. 15
B. 510
C. Syntax Error
D. 5

Solution

  1. Step 1: Analyze variable values and operation

    Variables a and b are 5 and 10, respectively. Adding them gives 15.
  2. Step 2: Understand output statement

    std::cout prints the value of c, which is 15, followed by a newline.
  3. Final Answer:

    15 -> Option A
  4. Quick Check:

    5 + 10 = 15 [OK]
Hint: Add variables before printing to find output [OK]
Common Mistakes:
  • Concatenating numbers as strings (510)
  • Expecting syntax error due to missing namespace
  • Printing only one variable instead of sum
4. Find the error in this C++ code snippet:
int main() {
    int* ptr;
    *ptr = 10;
    std::cout << *ptr << std::endl;
    return 0;
}
medium
A. Return type should be void
B. Missing semicolon after declaration
C. Incorrect use of std::cout
D. Pointer ptr is not initialized before use

Solution

  1. Step 1: Check pointer initialization

    Pointer ptr is declared but not assigned any address before dereferencing.
  2. Step 2: Understand consequences

    Dereferencing an uninitialized pointer causes undefined behavior or crash.
  3. Final Answer:

    Pointer ptr is not initialized before use -> Option D
  4. Quick Check:

    Uninitialized pointer = A [OK]
Hint: Always initialize pointers before dereferencing [OK]
Common Mistakes:
  • Ignoring pointer initialization
  • Thinking semicolon is missing
  • Assuming std::cout usage is wrong
5. Which feature of C++ allows it to be widely used in game development and system programming?
hard
A. Direct control over hardware and memory
B. Limited support for low-level programming
C. Automatic memory management like in Python
D. No support for object-oriented programming

Solution

  1. Step 1: Identify key features for games and systems

    Games and systems need fast, efficient code with hardware access.
  2. Step 2: Match feature to C++ capabilities

    C++ provides direct control over hardware and memory, unlike automatic management languages.
  3. Final Answer:

    Direct control over hardware and memory -> Option A
  4. Quick Check:

    Hardware control = C [OK]
Hint: Remember: games need speed and hardware control [OK]
Common Mistakes:
  • Confusing C++ with languages that have automatic memory management
  • Thinking C++ lacks low-level programming support
  • Believing C++ does not support object-oriented programming
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard