Essential C++ Interview Questions and Answers

Essential C++ Interview Questions and Answers for Freshers

COMMUNITY

7/17/202419 min read

woman sitting on armless chair with light between bookcases in room
woman sitting on armless chair with light between bookcases in room

Introduction to C++ and Its Importance in Interviews

C++ is a powerful, versatile programming language that has been a cornerstone of software development for decades. Developed by Bjarne Stroustrup in the early 1980s as an extension of the C programming language, C++ introduced object-oriented programming (OOP) concepts, which have since become fundamental in software engineering. Its rich feature set, including low-level memory manipulation, complex data structures, and high-performance capabilities, makes C++ a preferred language for various domains, such as systems programming, game development, and real-time simulations.

The significance of C++ in technical interviews cannot be overstated, particularly for freshers entering the software development industry. Its comprehensive nature allows interviewers to assess a candidate's understanding of both foundational programming principles and advanced concepts. Mastery of C++ demonstrates a proficiency in problem-solving, algorithmic thinking, and the ability to write efficient, optimized code. These skills are invaluable in a competitive job market where performance and reliability are critical.

Understanding C++ is not just about knowing syntax; it involves grasping the underlying principles of OOP, such as inheritance, polymorphism, encapsulation, and abstraction. These concepts are essential for building scalable and maintainable software. Moreover, C++'s compatibility with other programming paradigms, such as procedural and generic programming, further enhances its utility and relevance.

In modern software development, C++ continues to be a vital tool. It is widely used in developing operating systems, embedded systems, games, and real-time simulations, where performance and resource management are paramount. Many legacy systems are also written in C++, necessitating a deep understanding of the language for maintenance and enhancement. Consequently, proficiency in C++ opens numerous career opportunities across various industries.

Given its enduring relevance and comprehensive nature, C++ remains a staple in technical interviews. For freshers aiming to make a strong impression, a solid grasp of C++ can be a significant advantage, showcasing their capability to handle complex programming tasks and their readiness to tackle real-world software development challenges.

Basic C++ Syntax and Concepts

C++ is a powerful programming language known for its versatility and efficiency. For any fresher, understanding the basic syntax and core concepts of C++ is crucial. One of the first topics to master is data types, which define the kind of data a variable can hold. Common data types include int for integers, char for characters, float and double for floating-point numbers, and bool for Boolean values.

Variables act as storage containers for data. Declaring a variable in C++ is straightforward. For example, int age = 25; declares an integer variable named age and initializes it with the value 25. Operators, such as arithmetic operators (+, -, *, /), relational operators (==, !=, <, >), and logical operators (&&, ||, !), are used to perform operations on variables and values.

Control structures are essential for directing the flow of a program. The if-else statement is used to execute code blocks based on a condition. For instance:

if (age >= 18) {
    cout << "You are an adult.";
} else {
    cout << "You are a minor.";
}

The switch-case statement offers an alternative for multiple conditional branches, particularly when comparing a single variable to several constants. Loops are another critical concept. The for loop is ideal for iterating a specific number of times:

for (int i = 0; i < 10; i++) {
    cout << i << " ";
}

The while and do-while loops serve similar purposes but are used when the number of iterations is not known beforehand. Basic input/output operations in C++ are handled using cin for input and cout for output. For example:

int number;
cout << "Enter a number: ";
cin >> number;
cout << "You entered: " << number << endl;

Mastering these foundational elements is critical for writing simple and effective C++ programs, forming the bedrock upon which more complex concepts are built.

Object-Oriented Programming (OOP) in C++

Object-oriented programming (OOP) is a core paradigm in C++ that enables developers to build modular and reusable code by organizing software design around data, or objects, rather than functions and logic. Understanding OOP concepts is essential for any fresher looking to excel in C++ interviews. This section delves into key OOP concepts such as classes, objects, inheritance, polymorphism, encapsulation, and abstraction, which are fundamental to effective C++ programming.

A class in C++ is a blueprint for creating objects, encapsulating data for the object and methods to manipulate that data. For example, a simple class definition might look like:

```cppclass Rectangle {public: int width, height; Rectangle(int w, int h) { width = w; height = h; } int area() { return width * height; }};

In the example above, the class Rectangle includes two data members, width and height, and a method area that calculates the area of the rectangle. An object is an instance of a class, and it can be created as follows:

```cppRectangle rect(10, 5);

Inheritance in C++ allows a class (derived class) to inherit properties and behaviors from another class (base class). This promotes code reusability. For instance:

```cppclass Square : public Rectangle {public: Square(int side) : Rectangle(side, side) {}};

Polymorphism in C++ is the ability of a function or an object to take on many forms. It can be achieved through function overloading, operator overloading, and inheritance. There are two types of polymorphism: compile-time (e.g., function overloading) and run-time (e.g., virtual functions).

Encapsulation is the bundling of data and methods that operate on the data within one unit, such as a class. It restricts direct access to some of the object's components, which is a means of preventing unintended interference and misuse of the data. Abstraction, on the other hand, is the concept of hiding the complex implementation details and showing only the essential features of the object.

An interview question might ask you to explain the differences between various types of polymorphism or to write a simple class definition demonstrating inheritance. These questions aim to gauge your comfort level with OOP principles in C++. Mastering these concepts is crucial for developing efficient and maintainable C++ applications.

Advanced C++ Features and Techniques

In the realm of C++ programming, advanced features play a crucial role in developing efficient and robust applications. Among these features, templates, the Standard Template Library (STL), exception handling, and smart pointers stand out due to their significance and frequent discussion in technical interviews.

Templates provide a powerful mechanism for writing generic and reusable code. They allow functions and classes to operate with any data type without being rewritten for each one. Candidates should be prepared to explain the use of function templates and class templates, and understand template specialization and instantiation. For instance, they might be asked to demonstrate how to create a template function to swap two variables or a template class for a stack data structure.

The STL is an essential component of C++ that offers a collection of ready-to-use templates, including containers, iterators, algorithms, and function objects. Proficiency in STL demonstrates a candidate's ability to leverage these tools for efficient data manipulation. Interview questions could involve tasks like using STL containers such as vectors, lists, and maps, or applying algorithms like sort, find, and transform. Understanding the underlying mechanisms of iterators and the advantages of different containers also reflects a deeper grasp of STL.

Exception handling is another critical aspect of modern C++ programming. It provides a way to handle runtime errors gracefully and maintain the program's stability. Candidates should be familiar with the try, catch, and throw keywords, and the concept of exception propagation. They might need to illustrate how to create custom exception classes or manage resource cleanup using exception handling.

Smart pointers, introduced in C++11, are pivotal for effective memory management. They help avoid common pitfalls associated with manual memory management, such as memory leaks and dangling pointers. Candidates should understand the differences between unique_ptr, shared_ptr, and weak_ptr, and their appropriate use cases. Demonstrating the ability to manage dynamic memory using smart pointers is often a key focus in technical interviews.

Overall, mastery of these advanced C++ features and techniques not only showcases a candidate's technical proficiency but also their capability to write efficient, maintainable, and robust code.

Common C++ Programming Problems and Solutions

In the realm of C++ programming, practical problem-solving skills are paramount. Employers often evaluate candidates based on their ability to tackle a variety of common programming problems efficiently. Here, we present several typical questions that freshers may encounter, along with detailed solutions. These problems encompass areas such as sorting algorithms, searching techniques, string manipulation, and basic data structures like linked lists, stacks, and queues.

One prevalent problem is implementing sorting algorithms. For instance, candidates might be asked to write a C++ program using the Bubble Sort algorithm. Bubble Sort involves repeatedly stepping through the list, comparing adjacent elements, and swapping them if they are in the wrong order. This process is repeated until the list is sorted. Here’s a sample solution:

Bubble Sort Implementation:void bubbleSort(int arr[], int n) { for (int i = 0; i < n-1; i++) { for (int j = 0; j < n-i-1; j++) { if (arr[j] > arr[j+1]) { int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } }}

Another common question involves searching techniques, such as implementing Binary Search. Binary Search is an efficient algorithm for finding an element in a sorted array. It works by repeatedly dividing the search interval in half. If the value of the target is greater than the middle element, the search continues in the upper half, otherwise, it continues in the lower half.

Binary Search Implementation:int binarySearch(int arr[], int l, int r, int x) { while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1;}

String manipulation tasks are also common. A typical problem might involve reversing a string. The solution involves iterating through the string from both ends, swapping characters until the middle of the string is reached.

String Reversal Implementation:void reverseString(string &str) { int n = str.length(); for (int i = 0; i < n / 2; i++) { swap(str[i], str[n - i - 1]); }}

Finally, understanding data structures is crucial. For instance, implementing a basic stack using an array involves creating functions for common stack operations such as push, pop, and top.

Stack Implementation:class Stack { int top; int arr[MAX]; // MAX is the maximum size of the stackpublic: Stack() { top = -1; } bool push(int x) { if (top >= (MAX - 1)) { cout << "Stack Overflow"; return false; } else { arr[++top] = x; return true; } } int pop() { if (top < 0) { cout << "Stack Underflow"; return 0; } else { int x = arr[top--]; return x; } } int peek() { if (top < 0) { cout << "Stack is Empty"; return 0; } else { return arr[top]; } }};

These examples illustrate the type of practical problems that freshers might face in a C++ interview. By mastering these, candidates can effectively demonstrate their programming prowess and problem-solving capabilities.

Tips and Strategies for C++ Interview Preparation

Preparing for a C++ interview involves a combination of strategic study, practical practice, and mental preparation. Here are some actionable tips to help freshers navigate the preparation process effectively:

Effective Study and Practice

Begin by familiarizing yourself with the core concepts of C++, such as object-oriented programming, data structures, algorithms, and standard template libraries (STL). Books like "The C++ Programming Language" by Bjarne Stroustrup and "Effective C++" by Scott Meyers are invaluable resources. Complement these with online courses from platforms like Coursera, Udemy, or edX to gain a structured learning experience.

Utilize Coding Platforms

Practical coding is crucial for mastering C++. Utilize coding platforms such as LeetCode, HackerRank, and CodeSignal to practice coding problems. These platforms offer a wide range of problems that can help you improve your problem-solving skills and get accustomed to the types of questions asked in interviews. Regular practice on these platforms will also help you manage time efficiently during the actual interview.

Handling Different Types of Interview Questions

Interviews typically include questions on theoretical concepts, practical coding problems, and design-based scenarios. To handle theoretical questions, ensure you have a strong grasp of fundamental concepts. For coding problems, practicing on coding platforms will be beneficial. For design questions, understand common design patterns and practice designing systems or applications.

Avoid Common Pitfalls

One common pitfall is neglecting the basics. Ensure you can write clean, efficient code and understand the underlying principles of C++. Another pitfall is poor time management. Practice solving problems within a set timeframe to enhance your time management skills. Additionally, don't rush through questions; take your time to understand the problem before starting to code.

Build Confidence

Confidence comes from preparation and practice. Mock interviews can be a great way to simulate the interview environment and build confidence. Platforms like InterviewBit and Pramp offer mock interview sessions with peers or industry professionals. Furthermore, engaging in coding communities such as Stack Overflow and GitHub can provide additional insights and support.

By following these tips and strategies, freshers can enhance their preparation and increase their chances of success in C++ interviews. Consistent practice, effective time management, and a thorough understanding of C++ fundamentals are key to acing the interview.

Important Interview Question

Basics of C++

1. What is C++?

- C++ is a general-purpose programming language that is an extension of the C programming language. It provides support for object-oriented programming (OOP) features.

2. What are the key features of C++?

- Key features include classes, objects, inheritance, polymorphism, encapsulation, data abstraction, templates, exception handling, and the Standard Template Library (STL).

3. What is the difference between C and C++?

- C++ supports object-oriented programming while C is a procedural programming language. C++ has features like classes and objects, whereas C does not.

4. What is a class?

- A class is a user-defined data type in C++ that defines a blueprint for objects. It encapsulates data for the object and methods to operate on that data.

5. What is an object?

- An object is an instance of a class. It represents an entity in the real world that can be uniquely identified by its characteristics, behavior, and attributes.

6. What is inheritance?

- Inheritance is the mechanism in C++ by which one class acquires the properties (methods and attributes) of another class. It supports the concept of hierarchical classification.

7. What is polymorphism?

- Polymorphism allows objects of different classes to be treated as objects of a common superclass. It includes function overloading and function overriding.

8. What is encapsulation?

- Encapsulation is the bundling of data (variables) and methods (functions) that operate on the data into a single unit (class). It helps in data hiding and abstraction.

9. What is abstraction?

- Abstraction refers to the concept of hiding the complex implementation details and showing only the necessary features of an object. It is achieved using abstract classes and interfaces.

10. What are access specifiers in C++?

- Access specifiers (public, private, protected) determine the access rights for the members (variables and methods) of a class. They specify how the members can be accessed.

Variables and Data Types

11. What are the basic data types in C++?

- Basic data types include int, float, double, char, bool, void, etc.

12. What is the difference between int and unsigned int?

- `int` can store both positive and negative values, whereas `unsigned int` can only store non-negative values (from 0 to the maximum positive value for that type).

13. What is the difference between float and double?

- `float` is a single-precision floating-point type that typically occupies 4 bytes, while `double` is a double-precision floating-point type that typically occupies 8 bytes.

14. What is the difference between char and String in C++?

- `char` is a single character type, while `String` (from the `string` library) is a sequence of characters.

15. What are constants in C++?

- Constants are entities whose value doesn’t change during program execution. They are declared using the `const` keyword.

Control Structures

16. What are control structures in C++?

- Control structures are constructs that control the flow of execution in a program. Examples include if-else, switch-case, loops (for, while, do-while), etc.

17. What is the difference between while and do-while loop?

- `while` loop checks the condition before executing the loop body, whereas `do-while` loop executes the loop body first and then checks the condition.

18. How do you use the if-else statement in C++?

- The if-else statement is used to make decisions based on conditions. Syntax:

```cpp

if (condition) {

// statements if condition is true

} else {

// statements if condition is false

}

```

19. How do you use switch-case statement in C++?

- The switch-case statement is used to select one of many blocks of code to be executed. It evaluates an expression, matches the value of the expression to a case label, and executes the corresponding block of code.

```cpp

switch (expression) {

case constant1:

// statements

break;

case constant2:

// statements

break;

default:

// statements

}

```

20. What is a nested loop?

- A nested loop is a loop inside another loop. It allows for multiple iterations to be performed in sequence.

### Functions

21. What is a function in C++?

- A function is a block of code that performs a specific task. It is defined using a function declaration, function definition, and function call.

22. What is function overloading?

- Function overloading allows creating multiple functions with the same name but with different parameters. The compiler selects the appropriate function based on the arguments passed.

23. What is a default argument in C++?

- A default argument is a value provided in a function declaration that is automatically used if the caller does not provide a corresponding argument.

24. What is recursion?

- Recursion is the process in which a function calls itself directly or indirectly. It is useful for solving problems that can be broken down into smaller, similar sub-problems.

25. What is pass by value and pass by reference?

- Pass by value involves passing a copy of the actual parameters to the function. Pass by reference involves passing the address of the actual parameters, allowing direct access to the actual arguments.

### Arrays and Pointers

26. What is an array?

- An array is a collection of elements of the same data type stored in contiguous memory locations. It is accessed using an index.

27. How do you declare an array in C++?

- Syntax:

```cpp

type arrayName[arraySize];

```

28. What is the difference between an array and a pointer?

- An array is a fixed-size sequence of elements of the same type, while a pointer is a variable that stores the memory address of another variable.

29. What is a pointer?

- A pointer is a variable that stores the memory address of another variable. It allows for dynamic memory allocation and manipulation.

30. What is the difference between NULL and nullptr?

- `NULL` is a preprocessor macro defined as 0, typically used in C. `nullptr` is a keyword in C++11 that represents a pointer that does not point to any memory location.

Object-Oriented Programming (OOP)

31. What is object-oriented programming (OOP)?

- Object-oriented programming is a programming paradigm based on the concept of objects, which can contain data (attributes) and code (methods).

32. What are the pillars of OOP?

- The pillars of OOP are encapsulation, inheritance, and polymorphism.

33. What is a constructor?

- A constructor is a special member function of a class that is automatically called when an object of the class is created. It initializes the object’s data members.

34. What is a destructor?

- A destructor is a special member function of a class that is automatically called when an object goes out of scope or is explicitly deleted. It releases the resources held by the object.

35. What is the difference between a constructor and a destructor?

- A constructor is used to initialize the object, while a destructor is used to release resources when the object is destroyed.

36. What is operator overloading?

- Operator overloading allows defining the behavior of operators (like +, -, *, /) for user-defined types (objects) in C++.

37. What is a friend function?

- A friend function is a function that is not a member of a class but has access to the class’s private and protected members when explicitly declared as a friend.

38. What is a static member function?

- A static member function is a function that belongs to the class rather than instances of the class. It can be called using the class name without creating an object.

39. What is inheritance?

- Inheritance is the process by which one class inherits the properties (methods and attributes) of another class. It supports the concept of hierarchical classification.

40. What are access specifiers in inheritance?

- Access specifiers (public, private, protected) determine the visibility of the base class members in the derived class.

Polymorphism and Virtual Functions

41. What is polymorphism?

- Polymorphism allows objects of different classes to be treated as objects of a common superclass. It includes function overloading and function overriding.

42. What is function overloading?

- Function overloading allows creating multiple functions with the same name but with different parameters. The compiler selects the appropriate function based on the arguments passed.

43. What is function overriding?

- Function overriding occurs when a derived class provides a specific implementation of a method that is already defined in its base class.

44. What is a virtual function?

- A virtual function is a member function in a base class that is overridden in a derived class. It allows the function to be dynamically bound at runtime.

45. What is the difference between virtual function and pure virtual function?

- A virtual function is defined in a base class and overridden in a derived class. A pure virtual function is a virtual function that is

declared in a base class using `virtual` keyword and assigned to 0 (pure virtual function) which means that the derived class must implement it.

46. How do you declare a virtual function in C++?

- Syntax:

```cpp

virtual returnType functionName(parameters) {

// function body

}

```

47. Can a virtual function be inline?

- Yes, a virtual function can be declared as inline. However, its behavior will be determined by the actual object type at runtime.

48. What is early binding and late binding in C++?

- Early binding (or static binding) refers to the process of linking a function call with the code to be executed at compile time. Late binding (or dynamic binding) refers to linking at runtime, typically for virtual functions.

49. What is function overriding?

- Function overriding occurs when a derived class provides a specific implementation of a method that is already defined in its base class. It is achieved by using the `override` keyword in the derived class.

50. What is pure virtual function (abstract function)?

- A pure virtual function is a virtual function in a base class that is declared using `virtual` keyword and assigned to 0. It must be overridden by any derived class before the derived class can be instantiated.

### Templates and STL

51. What are templates in C++?

- Templates are used to create generic classes and functions in C++. They allow types to be parameterized so that a class or function can work with any data type.

52. What is a function template?

- A function template allows you to write a single function that can work with different data types. It is defined using the `template` keyword.

53. What is a class template?

- A class template allows you to create a generic class that can work with different data types. It is defined using the `template` keyword.

54. What is the Standard Template Library (STL)?

- The Standard Template Library (STL) is a powerful set of C++ template classes to provide general-purpose classes and functions with templates that implement many popular and commonly used algorithms and data structures like vectors, lists, queues, stacks, etc.

55. What are containers in STL?

- Containers in STL are used to store objects and data. Examples include vectors, lists, queues, stacks, etc.

56. What is the difference between vector and list?

- `vector` is a dynamic array that can resize itself automatically when an element is inserted or deleted, whereas `list` is a doubly linked list that allows for fast insertion and deletion of elements anywhere within the sequence.

57. What is an iterator in STL?

- An iterator is an object that is used to iterate through the elements of a container in STL. It acts as a pointer to the elements of the container.

58. What are algorithms in STL?

- Algorithms in STL are functions that operate on containers and perform operations like searching, sorting, counting, manipulating, and transforming elements.

59. Give an example of using an iterator in STL.

- Example:

```cpp

#include <iostream>

#include <vector>

int main() {

std::vector<int> vec = {1, 2, 3, 4, 5};

// Using iterator to print elements

std::vector<int>::iterator it;

for (it = vec.begin(); it != vec.end(); ++it) {

std::cout << *it << " ";

}

return 0;

}

```

60. What is the difference between `begin()` and `end()` in STL iterators?

- `begin()` returns an iterator pointing to the first element in the container, while `end()` returns an iterator pointing to the position just after the last element in the container.

### Exception Handling

61. What is exception handling?

- Exception handling is a mechanism to handle runtime errors (exceptions) gracefully without terminating the program.

62. What are the keywords used in exception handling?

- Keywords include `try`, `catch`, `throw`, and `finally` (in some languages, though not in C++).

63. How do you handle exceptions in C++?

- Exceptions are handled using `try`, `catch`, and `throw` blocks:

```cpp

try {

// code that may throw an exception

} catch (ExceptionType e) {

// handle the exception

}

```

64. Can you explain the concept of exception propagation?

- Exception propagation refers to the process where an exception thrown in a function is passed on to the calling function until it is caught or the program terminates.

65. What is the standard exception class in C++?

- The standard exception class in C++ is `std::exception`, which is defined in the `<exception>` header file.

### File Handling

66. What is file handling in C++?

- File handling involves reading from and writing to files. C++ provides streams (`ifstream`, `ofstream`, `fstream`) for file handling.

67. How do you open a file in C++?

- Syntax:

```cpp

#include <fstream>

std::ofstream outputFile;

outputFile.open("filename.txt");

```

68. How do you read from a file in C++?

- Example:

```cpp

#include <fstream>

#include <iostream>

std::ifstream inputFile("filename.txt");

std::string line;

while (std::getline(inputFile, line)) {

std::cout << line << std::endl;

}

inputFile.close();

```

69. How do you write to a file in C++?

- Example:

```cpp

#include <fstream>

std::ofstream outputFile("filename.txt");

outputFile << "Hello, World!";

outputFile.close();

```

70. What is the difference between `ifstream`, `ofstream`, and `fstream`?

- `ifstream` is used for reading input from a file, `ofstream` is used for writing output to a file, and `fstream` can be used for both reading and writing.

### Memory Management

71. What is memory management in C++?

- Memory management in C++ involves allocating and deallocating memory during program execution.

72. What is dynamic memory allocation?

- Dynamic memory allocation allows allocating memory at runtime using operators like `new` and `delete`.

73. How do you allocate memory dynamically in C++?

- Example:

```cpp

int *ptr = new int;

```

74. How do you deallocate memory in C++?

- Example:

```cpp

delete ptr;

```

75. What is a memory leak?

- A memory leak occurs when a program allocates memory dynamically but fails to deallocate it when it is no longer needed, leading to a gradual depletion of available memory.

### Preprocessor Directives

76. What are preprocessor directives?

- Preprocessor directives are special commands to the compiler that start with `#`. They are processed by the preprocessor before actual compilation begins.

77. Give an example of a preprocessor directive.

- Example:

```cpp

#include <iostream>

#define PI 3.14159

```

78. What is the difference between `#include <filename>` and `#include "filename"`?

- `#include <filename>` is used to include standard library headers, while `#include "filename"` is used to include user-defined headers.

79. What is the `#define` directive used for?

- The `#define` directive is used to define constants and macros.

80. What is conditional compilation?

- Conditional compilation allows compiling different parts of the program based on certain conditions using preprocessor directives like `#ifdef`, `#ifndef`, `#if`, `#else`, and `#endif`.

### Miscellaneous

81. What is the ternary operator in C++?

- The ternary operator `?:` is a shorthand version of the if-else statement. It takes three operands and evaluates a condition.

82. Give an example of the ternary operator.

- Example:

```cpp

int x = 5;

int y = (x > 3) ? 10 : 20; // y will be 10

```

83. What is the `sizeof` operator used for?

- The `sizeof` operator returns the size of a data type or a variable in bytes.

84. What is the scope resolution operator `::`?

- The scope resolution operator `::` is used to define the scope of a function or a variable in C++.

85. What are references in C++?

- References provide an alias or alternative name for an existing variable. They are declared using `&` symbol.

86. What is the difference between reference and pointer?

- A reference is an alias to an existing variable and cannot be `NULL`, whereas a pointer is a variable that stores the address of another variable and can be `NULL`.

87. What is `nullptr`?

- `nullptr` is a keyword introduced in C++11 to represent a null pointer.

88. What are the different types of casting in C++?

- Types include static_cast, dynamic_cast, const_cast, and reinterpret_cast for type conversions.

89. **What is

const correctness in C++?**

- Const correctness refers to using `const` keyword to ensure that variables or function parameters are not modified unintentionally.

90. What is the `mutable` keyword in C++?

- The `mutable` keyword is used to specify that a member variable of a `const` object can be modified.

### Advanced Concepts

91. What are smart pointers?

- Smart pointers are types that manage the memory allocation and deallocation automatically. Examples include `std::unique_ptr`, `std::shared_ptr`, and `std::weak_ptr`.

92. What is move semantics in C++?

- Move semantics allows transferring resources (like memory) from one object to another without copying.

93. What are lambda expressions in C++?

- Lambda expressions allow defining anonymous functions inline. They are denoted by `[]`.

94. What is multithreading in C++?

- Multithreading allows executing multiple threads simultaneously to achieve concurrent execution of tasks.

95. What are mutexes and locks in C++ multithreading?

- Mutexes are used to protect shared resources from being accessed simultaneously by multiple threads. Locks are used to lock and unlock mutexes.

96. What is RAII (Resource Acquisition Is Initialization) in C++?

- RAII is a programming technique where resources are acquired during object creation (in the constructor) and released during object destruction (in the destructor).

97. What is the `volatile` keyword used for in C++?

- The `volatile` keyword is used to indicate that a variable’s value may change at any time, even if it does not appear to be modified.

98. What are the different storage classes in C++?

- Storage classes include `auto`, `register`, `static`, `extern`, and `mutable`.

99. What is the `typeid` operator in C++?

- The `typeid` operator returns a reference to a `type_info` object that provides type identification at runtime.

100. What is the role of `namespace` in C++?

- Namespaces are used to organize code into logical groups and to prevent name collisions. They help in avoiding conflicts between different parts of a program.