Question-21. What is constructor ?
Answer- A constructor is the member function of the class which is having the same as the class name and gets executed automatically as soon as the object for the respective class is created.
Question-22. What is default constructor ? Can we provide one for our class ?
Answer- Every class does have a constructor provided by the compiler if the programmer doesn’t provides one and known as default constructor. A programmer provided constructor with no parameters is called as default constructor. In such case compiler doesn’t provides the constructor.
Question-23. What is the purpose of ‘delete’ operator ?
Answer- ‘delete’ operator is used to release the dynamic memory which was created using ‘new’ operator.
Question-24. Can I use malloc() function of C language to allocate dynamic memory in C++ ?
Answer- Yes, as C is the subset of C++, we can all the functions of C in C++ too.
Question-25. Can I use ‘delete’ operator to release the memory which was allocated using malloc() function of C language ?
Answer- No, we need to use free() of C language for the same.
Question-26. What is a friend function ?
Answer- A function which is not a member of the class but still can access all the member of the class is called so. To make it happen we need to declare within the required class following the keyword ‘friend’.
Question-27. What is a copy constructor ?
Answer- A copy constructor is the constructor which take same class object reference as the parameter. It gets automatically invoked as soon as the object is initialized with another object of the same class at the time of its creation
Question-28. Does C++ supports exception handling? If so what are the keywords involved in achieving the same.
Answer- C++ does supports exception handling. try, catch & throw are keyword used for the same.
Question-29.Explain the pointer- this ?
Answer- This, is the pointer variable of the compiler which always holds the current active object’s address.
Question-30. What is the difference between the keywords struct and class in C++ ?
Answer- By default the members of struct are public and by default the members of the class are private.