Which of the following C++ standards introduced smart pointers? 

  • C++03 
  • C++11 
  • C++14
  • C++98 
Smart pointers, like std::shared_ptr, std::unique_ptr, and std::weak_ptr, were introduced in C++11. They are part of the C++ Standard Library and are designed to manage the lifecycle of dynamically allocated objects, preventing memory leaks.

In terms of object-oriented design principles, what is typically the most significant critique against the use of friend functions? 

  • They break encapsulation. 
  • They increase execution time. 
  • They aren't necessary in OOP. 
  • They cause memory leaks.
Friend functions have the ability to access private and protected members of a class, which can be seen as a violation of the principle of encapsulation in object-oriented programming. While they offer flexibility, they can break the boundaries set by encapsulation.

You are building a configuration parser for a C++ application... 

  • Use std::ifstream and check its state 
  • Read entire file and validate before parsing 
  • Use regular expressions to parse 
  • Use std::fscanf
When using std::ifstream, it's possible to check the state of the stream (e.g., fail(), bad(), eof()) after operations. This allows for robust error handling by identifying issues like file corruption. Ensuring stream integrity before operations can prevent runtime issues.

Imagine you are developing a real-time gaming application where performance is critical. Which type of function (regular/inline) might you prefer to use for small, frequently-used utility calculations, and why? 

  • Regular functions due to easier debugging. 
  • Inline functions for performance optimization. 
  • Regular functions for better code organization. 
  • Inline functions due to easier maintenance.
Inline functions are usually preferred for small, frequently-used utility calculations in performance-critical applications like games because the compiler replaces the inline function call with the actual code, eliminating the overhead of a function call.

You are developing a financial application with various account types. How would you design the classes to achieve this and allow future modifications? 

  • Singleton Pattern 
  • Composition 
  • Prototype Pattern 
  • Inheritance and Polymorphism
Using inheritance, a base class 'Account' can be created with methods like 'withdraw', 'deposit', and 'calculateInterest'. Derived classes like 'SavingsAccount', 'CurrentAccount', etc., can then override these methods to provide specific implementations. Polymorphism ensures these methods are called appropriately.

What happens if an exception occurs in a destructor in C++? 

  • The program will retry the destructor 
  • A default destructor is called 
  • The program terminates 
  • The exception is ignored
If an exception is thrown from a destructor, and it's not caught within the destructor, the C++ runtime system will terminate the program. Destructors are often invoked during stack unwinding when an exception is thrown, so allowing exceptions to propagate out can lead to unpredictable behavior.

The return type of a function that does not return any value is specified as _______. 

  • char 
  • int 
  • double 
  • void
The "void" return type specifies that a function doesn't return a value. It's used when the primary purpose of the function is to perform an action, not produce data.

What happens if you try to delete memory using the delete operator more than once? 

  • It gets deleted twice 
  • No effect 
  • Program crashes 
  • Memory gets duplicated
Deleting a memory location more than once leads to undefined behavior, most commonly resulting in program crashes. Always ensure memory is deleted once and pointers are set to nullptr afterwards.

In which year was the C++98 standard officially published? 

  • 1990 
  • 1995 
  • 1998 
  • 2002
The C++98 standard was officially published in 1998. It was the first standardized version of the C++ language, providing a foundation for many modern C++ features and establishing a baseline for future improvements.

How is a friend class defined in C++? 

  • By inheriting the original class. 
  • By using the friendship keyword. 
  • By prefixing the class with the friend keyword. 
  • By including the class's header file in the original class.
A friend class in C++ is a class that is given permission to access the private and protected members of another class. To declare a class as a friend of another class, the friend keyword is used before the class declaration in the original class.