C++ Intermediate Skill Assessment Practice Test

Last Updated :
Discuss
Comments

Question 1

What are the four main principles of Object-Oriented Programming (OOP)?

  • A

    Inheritance, Polymorphism, Abstraction, Composition

  • B

    Inheritance, Polymorphism, Encapsulation, Abstraction

  • C

    Inheritance, Encapsulation, Aggregation, Composition

  • D

    Polymorphism, Encapsulation, Composition, Aggregation

Question 2

What is encapsulation in OOP?

  • A

    The ability to create a new class based on an existing class

  • B

    The process of combining data and functions into a single unit called a class

  • C

    The ability to use the same interface for different data types

  • D

    The process of hiding the implementation details and showing only the functionality

Question 3

What is polymorphism in OOP?

  • A

    The ability of a class to inherit from multiple classes

  • B

    The ability to redefine methods in derived classes

  • C

    The ability to use the same interface for different data types

  • D

    The ability to hide the implementation details of a class

Question 4

Which of the following is the recommended way to declare a function with parameters in C++?

  • A

    int function(a, b);

  • B

    int function();

  • C

    int function(int a, int b);

  • D

    function(int a, int b);

Question 5

Which among the following is the correct syntax for defining a function in C++?

  • A

    int function(int a, int b) { return a + b; }

  • B

    int function(int a, int b); { return a + b; }

  • C

    int function(int a, int b) return a + b;

  • D

    int function(int a, int b) { return a + b }

Question 6

What is std::string_view used for in C++?

  • A

    To provide a non-owning view of a string

  • B

    To format strings

  • C

    To print strings to the console

  • D

    To modify strings

Question 7

How to format a string using std::format in C++?

  • A

    std::format("{0} {1}", arg1, arg2)

  • B

    std::format("{1} {2}", arg1, arg2)

  • C

    std::format("{} {}", arg1, arg2)

  • D

    std::format("{0} {}", arg1, arg2)

Question 8

Which function is used to print formatted output to the console in C++20?

  • A

    std::cout

  • B

    std::printf

  • C

    std::print

  • D

    std::puts

Question 9

What is the default return type of a function in C++ if not specified?

  • A

    void

  • B

    int

  • C

    double

  • D

    Compilation error

Question 10

How to pass a parameter by reference in C++?

  • A

    void function(int* a)

  • B

    void function(int a)

  • C

    void function(int& a)

  • D

    void function(int&* a)

There are 50 questions to complete.

Take a part in the ongoing discussion