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 1

Next Page >
Question: What is the difference between C and C++?
Answer: C++ is an extension of C with additional features such as classes, inheritance, polymorphism, and templates, making it an object-oriented programming language.

Question: Can you explain the difference between 'malloc()' and new in C++?
Answer: Below please find the differences:

• The 'malloc()' is a function in C for dynamic memory allocation, while 'new' is an operator in C++ for dynamic memory allocation.
• Keyword 'new' automatically invokes constructors, while 'malloc()' does not.
• Additionally, new and delete ensure proper initialization and destruction of objects, whereas malloc() and free() do not invoke constructors or destructors.

Question: What is a constructor in C++ and how is it different from a normal member function?
Answer: A constructor is a special member function in a class that is automatically called when an object of that class is created. It initializes the object's state. It differs from a normal member function in that it has the same name as the class and has no return type.

Question: What is operator overloading?
Answer: Operator overloading allows operators to be redefined for user-defined types. For example, you can overload the '+' operator to add two objects of a class together.

Question: What is a virtual function?
Answer: A virtual function is a member function in a base class that is declared using the virtual keyword and can be overridden by derived classes. It allows for runtime polymorphism and dynamic binding, enabling the selection of the appropriate function to call based on the object's actual type.

Question: Can you explain the difference between 'delete' and 'delete[]' in C++?
Answer: Here are the differences:
• Keyword 'delete' is used to deallocate memory allocated using new, while 'delete[]' is used to deallocate memory allocated using 'new[]'.
• Using 'delete[]' ensures that the destructor of each object in the array is called.

Question: What is the difference between public, private, and protected access specifiers in C++ classes?
Answer: These access specifiers control the visibility of class members. Below please find their comparison:

• The 'public' members are accessible from outside the class.
• The 'private' members are only accessible within the class.
• The 'protected' members are accessible within the class and from its derived classes.

Question: What is a copy constructor?
Answer: A copy constructor is a special constructor that initializes a new object as a copy of an existing object of the same class. It is called when an object is passed by value, returned by value, or explicitly when creating a new object from an existing one.


Next Page >