Quiz: Introduction to C++ and OOP — 23 questions

Detailed questions and answers

1. Who created C++ at Bell Labs in 1985 as an extension of C with object-oriented features?

Dennis Ritchie
James Gosling
Bjarne Stroustrup
Guido van Rossum

Bjarne Stroustrup

Explanation

Bjarne Stroustrup created C++ at Bell Labs in 1985 by extending C with object-oriented features. Guido van Rossum is associated with Python, which was created later.

2. Which combination best characterizes C++ as a programming language?

Web-focused scripting, dynamic typing, and object-based programming without procedural features
Automatic memory management, interpreted execution, and a purely functional design
Near-assembly performance, manual memory control, and multiple programming paradigms
Hardware-level instructions, declarative syntax, and automatic garbage collection

Near-assembly performance, manual memory control, and multiple programming paradigms

Explanation

C++ combines high performance close to assembly, manual memory control, and procedural, object-oriented, and generic programming. Automatic garbage collection is associated with languages such as Java rather than with C++'s core memory model.

3. Which statement correctly compares machine language with high-level languages?

Machine language is designed for scripting, while high-level languages are designed for device drivers.
Machine language organizes programs around objects, while high-level languages organize them around procedures.
Machine language is closest to hardware, while high-level languages are more abstract and human-readable.
Machine language is more abstract, while high-level languages require direct processor instructions.

Machine language is closest to hardware, while high-level languages are more abstract and human-readable.

Explanation

Machine language has the lowest abstraction and is closest to hardware, whereas high-level languages provide greater abstraction and readability. The other choices confuse abstraction with programming paradigms or application domains.

4. A developer groups code around objects that combine data and behavior rather than around separate procedures; which programming paradigm is being used?

Declarative programming
Object-oriented programming
Functional programming
Procedural programming

Object-oriented programming

Explanation

Object-oriented programming organizes code around objects that represent data and behavior. Procedural programming instead structures code primarily around procedures or routines.

5. Which sequence correctly represents the main program development cycle?

Problem definition, coding, algorithm design, documentation, testing and debugging
Problem definition, algorithm design, coding, testing and debugging, documentation
Algorithm design, problem definition, coding, documentation, testing and debugging
Coding, problem definition, testing and debugging, algorithm design, documentation

Problem definition, algorithm design, coding, testing and debugging, documentation

Explanation

The cycle begins by defining the problem, then designs an algorithm, implements it through coding, tests and debugs the program, and documents the result. Coding follows the planning stages rather than preceding them.

6. What is the primary purpose of algorithm design before coding begins?

To translate completed source code into machine instructions for execution
To record explanations and usage instructions after the program is finished
To identify the program's requirements, inputs, outputs, and constraints
To represent the planned solution with tools such as flowcharts and pseudocode

To represent the planned solution with tools such as flowcharts and pseudocode

Explanation

Algorithm design specifies how to solve a problem and can use flowcharts and pseudocode before implementation. Identifying requirements belongs to problem definition, while translation and explanations occur in later development activities.

7. What is the primary role of a C++ compiler?

It places an executable into memory and begins its execution
It translates source code, checks errors, optimizes it, and can produce an executable
It executes source code step by step so programmers can inspect runtime behavior
It combines completed object files and libraries into a final executable

It translates source code, checks errors, optimizes it, and can produce an executable

Explanation

A compiler translates high-level C++ source code into machine-oriented code, checks errors, performs optimization, and may create an executable. A debugger instead executes code step by step to help inspect errors and behavior.

8. Which sequence correctly describes the main stages of C++ compilation?

Assembly produces .i, linking produces .s, preprocessing produces .obj, and compilation produces .exe
Compilation produces .i, preprocessing produces .o, linking produces .s, and assembly produces .exe
Preprocessing produces .i, compilation produces .s, assembly produces .o or .obj, and linking produces .exe
Preprocessing produces .s, compilation produces .o, assembly produces .exe, and linking produces .i

Preprocessing produces .i, compilation produces .s, assembly produces .o or .obj, and linking produces .exe

Explanation

C++ processing moves from the .cpp source through preprocessing to .i, compilation to .s, assembly to .o or .obj, and linking to an executable. The other sequences assign the file transformations to incorrect stages.

9. Which statement correctly distinguishes a linker from a loader?

A linker stores variables during execution, while a loader checks whether identifiers follow naming rules
A linker combines object files and resolves references, while a loader places the executable in memory and starts it
A linker debugs instructions step by step, while a loader translates source code into object files
A linker preprocesses headers, while a loader converts assembly instructions into object files

A linker combines object files and resolves references, while a loader places the executable in memory and starts it

Explanation

The linker combines object files, resolves external references, and creates an executable; the loader then places that executable in memory and starts it. Debugging, translation, variable storage, and preprocessing belong to other parts of development or execution.

10. What is a variable in C++?

A named memory location whose stored value can change during execution
A reserved keyword that identifies an executable instruction
A fixed memory location whose value is not intended to change
A function that combines separate data structures during compilation

A named memory location whose stored value can change during execution

Explanation

A variable is a named storage location in memory that holds a value capable of changing while the program runs. A constant represents a value not intended to change, while functions and keywords serve different purposes.

11. Which identifier is valid under the basic C++ variable-naming rules?

2ndTotal
total_count2
total count
class

total_count2

Explanation

A valid C++ variable name may begin with a letter or underscore and may then contain letters, digits, and underscores, making total_count2 valid. The other choices begin with a digit, contain a space, or use a reserved keyword.

12. Where is a local variable declared compared with a global variable?

A local variable is declared outside all functions, while a global variable is declared inside a function or block
A local variable is declared in a library, while a global variable is declared in an executable file
A local variable is declared during linking, while a global variable is declared during preprocessing
A local variable is declared inside a function or block, while a global variable is declared outside all functions

A local variable is declared inside a function or block, while a global variable is declared outside all functions

Explanation

A local variable is declared within a function or block, whereas a global variable is declared outside all functions. The distinction concerns declaration location and scope, not libraries, executables, or compilation stages.

13. How does object-oriented programming differ from procedural programming?

Object-oriented programming combines data with methods in objects, while procedural programming separates data from functions
Object-oriented programming separates data from methods, while procedural programming combines both within objects
Object-oriented programming organizes preprocessing stages, while procedural programming organizes memory addresses
Object-oriented programming focuses on executable files, while procedural programming focuses on loading libraries

Object-oriented programming combines data with methods in objects, while procedural programming separates data from functions

Explanation

Object-oriented programming binds data and methods together in objects, while procedural programming emphasizes functions with data separated from those functions. The other choices confuse programming paradigms with toolchain stages or reverse the central distinction.

14. Which set contains the four core principles of object-oriented programming?

Preprocessing, assembly, optimization, and execution
Compilation, linking, loading, and debugging
Encapsulation, inheritance, polymorphism, and abstraction
Variables, functions, libraries, and executables

Encapsulation, inheritance, polymorphism, and abstraction

Explanation

The four core OOP principles are encapsulation, inheritance, polymorphism, and abstraction. The other sets describe development processes or general programming elements rather than OOP principles.

15. What does encapsulation accomplish in object-oriented programming?

It creates reusable class hierarchies by deriving new classes from existing ones
It creates executable files by combining object files and external libraries
It converts high-level source code into machine instructions and checks for errors
It binds data and methods together while hiding internal implementation details

It binds data and methods together while hiding internal implementation details

Explanation

Encapsulation organizes data with the methods that operate on it and hides internal implementation details from outside code. Creating class hierarchies describes inheritance, while executable creation and translation belong to the C++ toolchain.

16. What does a C++ class provide without allocating memory for a particular object?

A pointer referring to allocated storage
A runtime copy of each member
A blueprint defining data and behavior
A storage block holding one instance

A blueprint defining data and behavior

Explanation

A class encapsulates data members and member functions as a blueprint for objects, but it does not allocate memory for an individual object. The storage block describes an object, which is an instance created from the class.

17. Which statement best describes an object in C++?

It is a function declaration shared by several classes
It is a type definition that describes possible members
It is a visibility rule controlling member access
It is an instance of a class that occupies memory

It is an instance of a class that occupies memory

Explanation

An object is a class instance, so it occupies memory and can be manipulated through the class’s defined properties and behaviors. A type definition describes a class rather than representing a stored instance.

18. Given `Widget* pointer` and `Widget object`, which expressions access a member named `value` through the pointer and the object, respectively?

`pointer->value` and `(*object).value`
`pointer.value` and `object->value`
`(*pointer)->value` and `object.value`
`pointer->value` and `object.value`

`pointer->value` and `object.value`

Explanation

The arrow operator accesses a member through a pointer, while the dot operator accesses a member through an object. The expression `pointer->value` is equivalent to `(*pointer).value`.

19. What is required when a C++ object is created on the heap with `new`?

A matching `delete` to release its memory
A dot operator to return its storage
A second constructor to reclaim its memory
A scope-resolution operator to destroy its members

A matching `delete` to release its memory

Explanation

Heap objects created with `new` require a matching `delete` so their allocated memory is released and a memory leak is avoided. Stack objects follow automatic destruction when their scope ends.

20. What does an access specifier control in a C++ class?

The visibility of members from different program contexts
The amount of memory reserved for each object
The kind of value stored by each data member
The order in which member functions execute

The visibility of members from different program contexts

Explanation

An access specifier determines where class data members and member functions can be accessed. A data type instead describes the kind of value a member stores, not its visibility.

21. From which locations can a public C++ member be accessed?

Inside its class and outside code, but not derived classes
Inside its class and derived classes, but not outside code
Inside its class, derived classes, and outside code
Inside unrelated classes, but not its own class

Inside its class, derived classes, and outside code

Explanation

Public members are available within the defining class, within derived classes, and from code outside the class. The restriction against outside access applies to private or protected members, not public ones.

22. Which access pattern correctly describes a protected C++ member?

Accessible in its class and outside code, but not derived classes
Accessible in its class and derived classes, but not outside code
Accessible in unrelated classes but hidden from derived classes
Accessible from every function that includes the class definition

Accessible in its class and derived classes, but not outside code

Explanation

Protected members can be used by the defining class and its derived classes, while external code cannot access them directly. Public members, unlike protected members, can be accessed from outside the class.

23. Which statement correctly describes private access and default access in C++?

Private members are unavailable inside their class; both class and struct default to public
Private members are available to derived classes; both class and struct default to private
Private members are available outside code; class defaults to public and struct to private
Private members are class-local; class defaults to private and struct to public

Private members are class-local; class defaults to private and struct to public

Explanation

Private members are accessible within their defining class, and C++ gives classes a default private access level while structs default to public. Derived classes and outside code therefore do not receive direct access to private members by default.

Review with flashcards

Memorize the answers with 48 flashcards on Introduction to C++ and OOP.

Who created C++ and when?

Bjarne Stroustrup created C++ in 1985.

Where was C++ created?

At Bell Labs.

What programming paradigms does C++ combine?

Object-oriented, generic, and procedural programming.

See flashcards →

Read the study sheet

Read the complete study sheet on Introduction to C++ and OOP.

See study sheet →

Similar courses

Create your own quizzes

Import your course and AI generates quizzes with corrections in 30 seconds.

Quiz generator