Loading...

C++ Programming Interview Questions

This article is mainly focused on the most repeatedly asked and the latest updated questions.

C++ Interview Questions Set-4

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:
1. Operator overloading: Operator overloading is a compile-time polymorphism in which a standard operator is overloaded to provide a user-defined definition to it. For example, '+' operator is overloaded to perform the addition operation on data types such as int, float, etc.
Operator overloading can be implemented in the following functions:
  • Member function
  • Non-member function
  • Friend function
2. Function overloading: Function overloading is also a type of compile-time polymorphism which can define a family of functions with the same name. The function would perform different operations based on the argument list in the function call. The function to be invoked depends on the number of arguments and the type of the arguments in the argument list.


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.


- Related Topics