Commonly Asked C++ Programming Interview Questions | Set 4
31. What is overloading?
Ans:
- When a single object behaves in many ways is known as overloading. A single object has the same name, but it provides different versions of the same function.
- C++ facilitates you to specify more than one definition for a function name or an operator in the same scope. It is called function overloading and operator overloading respectively.
- Overloading is of two types:
Operator overloading can be implemented in the following functions:
- Member function
- Non-member function
- Friend function
32. What is type casting in C++?
Ans: Type casting in C is used to change the data type. They are of two types: Implicit Type Conversion: It is automatic. Explicit Type Conversion: It is user-defined.
33. What is stream in C++?
Ans: Stream refers to a stream of characters to be transferred between program thread and i/o.
34. What is function overriding?
Ans: If you inherit a class into a derived class and provide a definition for one of the base class's function again inside the derived class, then this function is called overridden function, and this mechanism is known as function overriding.
35. What is virtual inheritance?
Ans: Virtual inheritance facilitates you to create only one copy of each object even if the object appears more than one in the hierarchy.
36. Can we overload a destructor?
Ans: No, a destructor cannot be overloaded, and it has the only form without the parameters.
37. What is the main difference between the keyword struct and class?
Ans: The keyword struct is used for resembling public members by default, while the keyword class is used for resembling private members by default.
38. What are the differences between C and C++?
Ans:
1) C++ is a kind of superset of C, most of C programs except few exceptions work in C++ as well.
2) C is a procedural programming language, but C++ supports both procedural and Object Oriented programming.
3) C++ supports references , C doesn’t.
4) Since C++ supports object oriented programming, it supports features like function overloading, templates, inheritance, virtual functions, friend functions. These features are absent in C.
5) C++ supports exception handling at language level, in C exception handling is done in traditional if-else style.
6) In C, scanf() and printf() are mainly used input/output. C++ mainly uses streams to perform input and output operations. cin is standard input stream and cout is standard output stream.
39. What is the purpose of the "delete" operator?
Ans: The "delete" operator is used to release the dynamic memory created by "new" operator.
40. What does Scope Resolution operator do?
Ans: A scope resolution operator(::) is used to define the member function outside the class.