C++ Interview Question and Answers

76. What is the difference between a vector and a map?
  A vector is a sequential container, i.e., all the elements are in a sequence, whereas a map is an association container, i.e., all elements are stored in the form of a key value association pair.
 
Your Name Your Email-ID
Your Answer
77. What are the advantages of using cin and cout compared to scanf(...) and printf(...), respectively?
 
  • Compared to the standard C functions printf() and scanf(), the usage of the cin and cout is more type safe.
  • The format strings, which are used with printf() and scanf() can define wrong format specifies for their arguments, for which the compiler does not warn.
  • In contrast, argument checking with c in and cout is performed by the compiler.
  • C in and Cout are stream classes that could be used to receive and print objects respectively.
 
Your Name Your Email-ID
Your Answer
78. Explain copy constructor?
  A copy constructor is a special type of constructor which initializes all the data members of the newly created object by copying the contents of an existing object. The compiler provides a default copy constructor.
Class_name new _ object ( existing object);
 
Your Name Your Email-ID
Your Answer
79. What are the advantages of operator overloading?
  Operator overloading is used to provide some extra features, behaviors and abilities to the users of a particular class. This feature in C++ helps in controlling the functions performed by an operator and reduces the chance of occurrence of errors in a program.
 
Priya,says Feb 23,2014
Operator overloading makes user defined types to be used like built in data types. It provides the programmer with more flexibility and comprehensibilty.
Your Name Your Email-ID
Your Answer
80. What is a dangling pointer?
  When the location of the deallocated memory is pointed by the pointer even after the deletion or allocation of objects is done, without the modification in the value of the pointer, then this type of pointer is called a dangling pointer.
 
Your Name Your Email-ID
Your Answer