C++ Interview Question and Answers

31. What is difference between function overloading and operator overloading?
  A function is overloaded when same name is given to different function.
While overloading a function, the return type of the functions need to be the same.
 
Abhishek, said May 29,2014
Function Overloading: 1. Used when different implementations of the same functionality are provided based on the datatype and/or number of arguments. 2. Same function name. 3. Different signature. 4. Number and/or Type and/or Sequence of arguments must differ in different implementations. 5. Return type is not important as it is not mandatory to collect the return value by the caller. 6. Happens at compile time. Operator Overloading: 1. Used when same operator needs to be redefined to work with custom datatype. 2. Precedence, Associativity cannot be changed. 3. Logical behavior of the operator should be kept intact to avoid ambiguity. 4. Atleast one operand should be custom defined. 5. Happens at Run-time.
Ravindra Dhakad, said Jan 30, 2014
Function overloading helps the user to define various functions with the same name but the all the overloaded functions must have different arguments. While operator overloading helps the user to define the given operator in a different way. operator overloading can only be done in class variables.
Naresh JANGRA, said July 22,2014
Function overloading in which many function has same name but in operator overloading we can use a single operator but the working of operator is different.for example + where A+b=Ab and 2+3=5.
Your Name Your Email-ID
Your Answer
32. What are the advantages of inheritance?
 
  • Code reusability
  • Saves time in program development.
 
Your Name Your Email-ID
Your Answer
33. What is a dynamic constructor?
 
  • The constructor can also be used to allocate memory while creating objects.
  • Allocation of memory to objects at the time of their construction is known as dynamic construction of objects.
  • The memory is allocated with the help of the new operator.
 
Your Name Your Email-ID
Your Answer
34. What is the difference between an Array and a List?
  The main difference between an array and a list is how they internally store the data. whereas Array is collection of homogeneous elements. List is collection of heterogeneous elements.
 
Sachin Mote, said Apr 1, 2018
There are couple of more differences as well
1) in arrays there is no bound checking where as in linked list we can store as many elements we wish.
2) in case of arrays we can directly go to the desired element by using index where as in linked list we need to traverse the entire list.
Sayantan Panja, said May 29,2014
In array, elements are stored in continuous memory location but in case of list [e.g linked list] they are stored at any available memory locations which are pointed from the previous memory pointer.
Your Name Your Email-ID
Your Answer
35. What is the use of ‘using’ declaration?
  A using declaration makes it possible to use a name from a namespace.
 
Your Name Your Email-ID
Your Answer