April 29, 2013

C/C++ Programming interview questions and answers

What is default constructor?
Ans- Constructor with no arguments or all the arguments has default values.


What is copy constructor?
Ans- Constructor which initializes the it's object member variables ( by shallow copying) with another object of the same class. If you don't implement one in your class then compiler implements one for you.
for example:
Boo Obj1(10); // calling Boo constructor
Boo Obj2(Obj1); // calling boo copy constructor
Boo Obj2 = Obj1;// calling boo copy constructor


When are copy constructors called?
Ans- Copy constructors are called in following cases:
a) when a function returns an object of that class by value
b) when the object of that class is passed by value as an argument to a function
c) when you construct an object based on another object of the same class
d) When compiler generates a temporary object



What is assignment operator?
Ans- Default assignment operator handles assigning one object to another of the same class. Member to member copy (shallow copy)



What are all the implicit member functions of the class? Or what are all the functions which compiler implements for us if we don't define one.??
Ans- default ctor
copy ctor
assignment operator
default destructor
address operator

0 comments:

Post a Comment

  • Blogger news

    This Blog Contains All Topics Related To Internet, Website Help, Interview Questions, News, Results From Various Resources, Visit Daily For More Interesting And Famous Topics.
  • Random Post

  • About

    We Provide All Information Which you Needed. We Maintain This Blog Very Carefully, If You Find Any Mistake or Any Suggestions Then Please Let Us Know, You Can Contact Us By Comments, On FB Page Or On Google+ Page. ~ Thank You