Reference Page: C-Language|C++|C#|VB.Net|Asp.Net

C++ Links : Learn     Interview Questions     Software IDE C++ Jobs : Indeed.com     ZipRecruiter.com     Monster.com

C++ Interview Questions - Page 3

< Previous Page              Next Page >
Question: What is the difference between 'std::vector' and 'std::array' in C++?
Answer: The 'std::vector' is a dynamically resizable array that manages its memory automatically, whereas 'std::array' is a fixed-size array whose size is known at compile time.
Additionally, 'std::array' is more efficient in terms of memory and performance for fixed-size arrays.

Question: What is the role of the 'mutable' keyword in C++?
Answer: The 'mutable' keyword is used to declare a member variable of a class that can be modified even if the containing object is declared as const. This allows changing the value of the mutable member variable within const member functions.

Question: What is a 'lambda expression' in C++?
Answer: A lambda expression is an anonymous function that can capture variables from the surrounding scope and be used as arguments to functions, especially algorithms like std::sort and std::for_each. It provides a concise way to define inline functions.

Question: What is RAII (Resource Acquisition Is Initialization)?
Answer: RAII is a programming idiom in C++ where resource management is tied to object lifetime. Resources (such as memory, file handles, and locks) are acquired during object construction and released during object destruction, ensuring proper cleanup even in the presence of exceptions.

Question: Can you explain the difference between 'reinterpret_cast', 'static_cast', 'dynamic_cast', and 'const_cast'?
Answer: Here is the comparison:
• reinterpret_cast: Performs low-level type conversions between pointer types, but it is unsafe and should be used with caution.
• static_cast: Performs conversions between related types, such as implicit conversions and narrowing conversions.
• dynamic_cast: Performs safe downcasting in polymorphic class hierarchies at runtime, returning nullptr if the conversion fails.
• const_cast: Adds or removes const or volatile qualifiers from a pointer or reference

Question: What are inline functions in C++?
Answer: Inline functions are functions that are expanded in place at each point they are called, instead of being executed as separate function calls. They should be used for small, frequently called functions to reduce function call overhead.

Question: What is the difference between 'std::move' and 'std::forward' in C++?
Answer: The 'std::move' is used to cast an object to an rvalue, enabling the move semantics and efficient transfer of resources.
Whereas 'std::forward' is used to preserve the value category (lvalue or rvalue) of a forwarded argument in a templated function..

Question: Can you explain the concept of multiple inheritance in C++?
Answer: In C++ multiple inheritance allows a class to inherit from more than one base class. It can lead to the "diamond problem" where ambiguity arises due to the presence of shared base classes, which can be resolved using virtual inheritance.

Question: What is the 'std::move' constructor and when is it implicitly declared?
Answer: The 'std::move' constructor is a special constructor that enables move semantics for a class. It is implicitly declared by the compiler if the class does not explicitly declare any of its own move constructors, copy constructors, copy assignment operators, or destructors.


< Previous Page Next Page >