Commonly Asked C++ Programming Interview Questions | Set 6
51. What is the difference between delete and delete[]?
Ans: Delete [] is used to release the array of allocated memory which was allocated using new[] whereas delete is used to release one chunk of memory which was allocated using new.
52. Can we have a String primitive data type in C++?
Ans: No, we cannot have a String Primitive data type in C++. Instead, we can have a class from the Standard Template Library (STL).
53. Explain how functions are classified in C++ ?
Ans: In C++ functions are classified as
- Return type
- Function Name
- Parameters
- Function body
54. What is endl in C++?
Ans: Endl is a predefined object of ostream class to insert a new line characters.
55. Which operators can be overloaded in C++?
Ans: List of operators that can be overloaded are:
+ , – , * , / , % , ^, & , | , ~ , !, =, ++ , –, ==, != , && , ||
+= , -= , /= , %= , ^= , &=, |= , *= , = , [] , (), ->, ->* , new , new [] , delete , delete []
56. List all types of inheritance supported in C++
Ans:
- Single
- Multilevel
- Multiple
- Hierarchical
- Hybrid
57. What is Pure Virtual Function?
Ans: A pure virtual function is a virtual function which does not contain any definition. The normal virtual function is preceded with a keyword virtual. Whereas the pure virtual function is preceded with the keyword virtual and ended with the value 0.
Example: virtual void add() = 0;
58. Define an Abstract class in C++?
Ans: An abstract class in C++ is referred to as the base class, which has at least one pure virtual function. In such a function, a person cannot instantiate an abstract class. This way, an Abstract class a pure virtual function is defined by using a pure specifier which is equal to zero during the declaration of the virtual member function in the class declaration.
59. Explain what is a reference variable in C++?
Ans: A reference variable is just like a pointer with few differences. It is declared using & Operator. In other words, reference is another name for an already existing variable.
60. Which access specifier/s can help to achieve data hiding in C++?
Ans: Private & Protected.