The Tricky C++ Quiz Quiz

  1. Pointers and References

    What is the key difference between a pointer and a reference in C++?

    1. A pointer must be initialized, while a reference cannot be re-assigned.
    2. A reference can be null, while a pointer cannot.
    3. A pointer can be re-assigned to point to a different object, while a reference cannot be re-seated after initialization.
    4. There is no difference; pointers and references are identical.
    5. A referance can be re-assigned to point to a different object, while a pointer cannot.
  2. Virtual Functions

    What is the primary purpose of using virtual functions in C++?

    1. To improve compile-time performance.
    2. To enable polymorphism and dynamic dispatch.
    3. To reduce memory usage.
    4. To prevent inheritance.
    5. To enforce static typing.
  3. Memory Management

    Which keyword is used to allocate dynamic memory in C++?

    1. malloc
    2. allocate
    3. new
    4. create
    5. memory
  4. Templates

    What is the main advantage of using templates in C++?

    1. To avoid compile-time errors.
    2. To write generic code that works with different data types.
    3. To reduce the size of the executable.
    4. To improve runtime performance by eliminating function calls.
    5. To enforce object-oriented programming principles.
  5. Constructors

    What is the purpose of a constructor in a C++ class?

    1. To destroy objects.
    2. To initialize the object's data members.
    3. To allocate memory for the object.
    4. To define the object's methods.
    5. To prevent inheritance.
  6. Inheritance

    What is multiple inheritance in C++?

    1. A class inheriting from a single base class multiple times.
    2. A class inheriting from two or more base classes.
    3. A class inheriting from a derived class.
    4. A function overloading multiple times.
    5. A constructor overloading multiple times.
  7. Exception Handling

    What is the purpose of the 'try' and 'catch' blocks in C++ exception handling?

    1. To define global variables.
    2. To define a macro.
    3. To handle errors and prevent program termination.
    4. To optimize code execution.
    5. To declare namespaces.
  8. The Standard Library

    Which standard library provides input/output functionalities in C++?

    1. stdio.h
    2. iostream
    3. stdlib.h
    4. math.h
    5. string.h
  9. Operator Overloading

    What does operator overloading allow you to do in C++?

    1. Create new operators.
    2. Change the precedence of operators.
    3. Define custom behavior for operators when used with user-defined types.
    4. Remove operators from the language.
    5. Disable operators.
  10. Namespaces

    What is the primary purpose of using namespaces in C++?

    1. To improve code execution speed.
    2. To group related classes together.
    3. To avoid name collisions between identifiers from different libraries.
    4. To reduce memory usage.
    5. To simplify debugging.