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 2

< Previous Page              Next Page >
Question: What is a destructor in C++?
Answer: A destructor is a special member function in a class that is automatically called when an object is destroyed or goes out of scope. It is used to release resources allocated by the object and perform cleanup operations. The destructor's name is the same as the class name preceded by a tilde (~).

Question: What is the difference between a pointer and a reference in C++?
Answer: A pointer is a variable that stores the memory address of another variable, while a reference is an alias for an existing variable. Pointers can be reassigned and can point to nothing (nullptr), whereas references cannot be reassigned after initialization and must always refer to an object.

Question: What is dynamic polymorphism in C++?
Answer: Dynamic polymorphism, also known as runtime polymorphism, allows a base class pointer or reference to invoke overridden methods of derived classes at runtime.
It is achieved through virtual functions and dynamic binding.

Question: What is the 'const' keyword in C++?
Answer: The 'const' keyword in C++ is used to declare constants or to specify that an object or a member function does not modify the object's state. It can be applied to variables, pointers, references, and member functions.

Question: Can you explain the concept of function overloading in C++?
Answer: Function overloading allows multiple functions with the same name but different parameter lists to coexist in the same scope. The compiler determines which function to call based on the number and types of arguments passed to it.

Question: What are templates in C++?
Answer: 'Templates' are a feature of C++ that allows for generic programming. They enable the creation of functions and classes that work with any data type.

Templates are instantiated with specific data types at compile-time.

Question: What is the difference between shallow copy and deep copy?
Answer: The Shallow copy creates a new object and copies the values of all fields, including pointers, from the original object to the new object. Deep copy, on the other hand, creates a new object and recursively copies all dynamically allocated memory pointed to by pointers in the original object, resulting in distinct copies of all dynamically allocated data.

Question: What are smart pointers in C++?
Answer: Smart pointers are objects that mimic raw pointers but provide automatic memory management and prevent memory leaks. They include following from the C++ Standard Library:
std::unique_ptr
std::shared_ptr
std::weak_ptr


< Previous Page Next Page >