CS304 - Object Oriented Programming Final Term Short Question & Answers (Lecture 19 to 45)
CS304 - Object Oriented Programming Final Term Short Question & Answers (Lecture 19 to 45)
Q1: What is the purpose of overloading the stream insertion (<<) and extraction (>>)
operators?
To allow objects of user-defined classes to be input and output using cin and cout, just like
built-in types.
Q3: What is the difference between pre-increment (++obj) and post-increment (obj++)
operators?
Pre-increment increments then returns the new value, while post-increment returns the original
value then increments.
A function declared in a base class that can be overridden in derived classes to achieve runtime
polymorphism.
A virtual function set to 0 in the base class, making the class abstract and requiring derived
classes to override it.
To ensure the proper destructor is called when deleting a derived class object through a base
class pointer.
A blueprint for creating generic classes or functions that can work with different data types.
A blueprint for creating a family of classes that can work with different data types.
Providing a specific implementation for a template when used with a particular data type.
An object that provides a way to access elements of a container sequentially without exposing
the underlying structure.
An object that stores a collection of other objects and organizes them in a well-defined way.
Q18: What is the difference between sequence containers and associative containers?
Sequence containers store elements in a linear sequence, while associative containers store
elements in a way that allows fast retrieval based on keys.
Q21: What are the keywords used for exception handling in C++?
The process of destroying local objects and calling destructors for automatic objects when an
exception is thrown.
Q27: What is the advantage of using function objects over regular functions?
Function objects can maintain state between calls and can be customized through their member
variables.
An object that acts like a pointer but provides additional features such as automatic memory
management.
Q31: What are the three main types of smart pointers in C++11?
To manage a single object and ensure it is deleted when the unique_ptr goes out of scope.
A special constructor that transfers ownership of resources from one object to another instead
of copying.
An assignment operator that transfers ownership of resources from one object to another
instead of copying.
A function that the compiler will automatically generate if it is used but not explicitly defined.
A function that is not a member of a class but has access to its private and protected members.
A class whose members have access to the private and protected members of another class.
Q44: What is the purpose of the const keyword when used with member functions?
To indicate that the function will not modify the object's state.
A data member that belongs to the class rather than to any specific object of the class.
A function that belongs to the class rather than to any specific object of the class.
A declarative region that provides a scope for the identifiers inside it.
The default access specifier for members and bases is public for struct and private for class.
A class that contains at least one pure virtual function and cannot be instantiated.
An ambiguity that arises when a class inherits from two classes that have a common base class.
A way to solve the diamond problem by ensuring only one instance of the common base class is
inherited.
To indicate that a variable may change unexpectedly, preventing certain compiler optimizations.
If a class defines any of the copy constructor, copy assignment operator, or destructor, it should
probably explicitly define all three.
An extension of the rule of three that includes move constructor and move assignment operator.
A constructor that calls another constructor of the same class to do part of the initialization.
A special class type where all members share the same memory location.
Q70: What is the difference between a C-style enum and a C++11 enum class?
An enum class provides stronger type safety and doesn't allow implicit conversions to int.
A reference must be initialized when declared and cannot be null, while a pointer can be null
and can be reassigned.
Run-Time Type Information, a feature that exposes information about an object's data type at
runtime.
A version of the new operator that constructs an object at a specific memory address.
A class that has compiler-provided default constructor, copy constructor, copy assignment
operator, and destructor.
Plain Old Data type, a class or struct that is both trivial and standard-layout.
A technique to pass arguments to another function while preserving their value category
(lvalue/rvalue).
A feature introduced in C++11 that provides a consistent syntax for initialization of objects.
A control structure that iterates over all elements in a range without using an explicit iterator.
A feature that allows the compiler to deduce the type of a variable from its initializer.
A keyword that yields the type of its operand, which is useful in generic programming.
A syntax for writing function declarations where the return type comes after the parameter list.
An enumeration where the enumerators are only accessible through the enumeration name.
An initializer for a non-static data member that is used if the member is not initialized by a
constructor.
A constructor that calls another constructor in the same class as part of the initialization.
A feature that allows a derived class to inherit constructors from its base class.
A feature that allows you to define your own suffixes for literals.
A namespace that allows its members to be treated as if they were members of the enclosing
namespace.
A variable that has thread storage duration, meaning each thread has its own copy.
A keyword representing a null pointer literal, which is more type-safe than using 0 or NULL.