C++ Interview Question and Answers

16. What are the few advantages of Inline function?
 
  • It offers an improved macro facility.
  • By using the inline functions, the user can split a large function with many nested modules of statement blocks into many small inline functions.
 
Vaishu,says Mar 27, 2014
The difference between an inline function and a regular function is that wherever the compiler finds a call to an inline function, it writes a copy of the compiled function definition. However, with a regular function, a normal function call is generated. This eliminated overhead of too many function calls.
Sruthi,says Feb 03,2014
Inline function reduces the ovehead of using stack and other data structures which are used while calling functions.
Your Name Your Email-ID
Your Answer
17. What is copy constructor?
  Copy constructor is a constructor function with the same name as the class and used to make deep copy of objects.
 
Gaurav,says Aug 24, 2014
A copy constructor is a special constructor in the C++ programming language for creating a new object as a copy of an existing object.
Amitesh, said Feb 28, 2014
The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to: Initialize one object from another of the same type. Copy an object to pass it as an argument to a function. Copy an object to return it from a function. If a copy constructor is not defined in a class, the compiler itself defines one.If the class has pointer variables and has some dynamic memory allocations, then it is a must to have a copy constructor.
Your Name Your Email-ID
Your Answer
18. What is default constructor?
  A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.
 
Abhishek, said May 29,2014
If we don't define an explicit constructor for the class, compiler will provide a default no argument constructor. But if we dine even one constructor and we want the default constructor feature as well, then we need to explicitly define one.
Your Name Your Email-ID
Your Answer
19. What is a scope resolution operator?
  The scope resolution operator permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.
 
Amirul,says May 20,2017
Scope resolution operator(::) is used to define a function outside a class or when we want to use a global variable but also has a local variable with same name.
Your Name Your Email-ID
Your Answer
20. What is the difference between Object and Instance?
 
  • An instance of a user-defined type is called an object. We can instantiate many objects from one class.
  • An object is an instance of a class.
 
Your Name Your Email-ID
Your Answer