C++ Interview Question and Answers

11. Define Constructors?
  A constructor is a member function with the same name as its class. The constructor is invoked whenever an object of its associated class is created.It is called constructor because it constructs the values of data members of the class.
Rahul Srivastava,says Feb 26, 2014
A constructor is a special member function of a class that is having same name as that of class. It does not have a return type and it is automatically invoked on the time of object creation. Constructors are mainly use to initialize the data members of an object. If we do not define a constructor in our program even then it is provided by the language compiler by default. There may be three types of constructor
Default Constructor
Parameterized Constructor
Copy Constructor.
Your Name Your Email-ID
Your Answer
12. How variable declaration in c++ differs that in c?
  C requires all the variables to be declared at the beginning of a scope but in c++ we can declare variables anywhere in the scope. This makes the programmer easier to understand because the variables are declared in the context of their use.
Krishna,says Mar 30, 2014
Not required with the latest C compilers. The latest GCC compilers provide you an option of declaring the variables anywhere in the program before they get used.
Your Name Your Email-ID
Your Answer
13. Define destuctors?
  • A destructor is called for a class object when that object passes out of scope or is explicitly deleted.
  • A destructors as the name implies is used to destroy the objects that have been created by a constructors.
  • Like a constructor , the destructor is a member function whose name is the same as the class name but is precided by a tilde.
Harshbardhan Patel,says Mar 27, 2014
A destructor is a special member function of a class that is executed whenever an object of it\'s class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class. A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc.
Your Name Your Email-ID
Your Answer
14. What is a class?
  A class is a collection of objects.
Mohammed Shakeel,says Sep 26, 2014
A class is a collection of objects whereas object is a collection of data member, member function.
Nilesh, said Jan 01, 2014
Class is collection of not only class but also data member, member function.
Your Name Your Email-ID
Your Answer
15. what is the difference between c & c++?
    C++ ia an object oriented programing but C is a procedure oriented programing.
  • C is super set of C++.
  • C can’t suport inheritance, function overloading, method overloading etc. but c++ can do this.
  • In c program the main function could not return a value but in the c++ the main function shuld return a value.
Ashok Shah,says July 10,2017
C is a sub-set of C++ not a superset. C++ is a superset of C.
Your Name Your Email-ID
Your Answer