Question 1 of 25
Hints left: 3
Q1
Which type of constructor is automatically called when an object is created without any arguments in C++?
Q2
What is the difference between a constructor and a normal member function in C++?
Q3
What is the purpose of the 'explicit' keyword before a constructor in C++?
Q4
Which of the following statements about destructors in C++ is true?
Q5
What is a constructor in C++?
Q6
What happens if a class does not define any constructors in C++?
Q7
What is the access specifier that allows members of a class to be accessed from anywhere in the program in C++?
Q8
What is a constructor initialization list in C++?
Q9
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class complex { int i; int j; public: complex(){} complex(int a, int b) { i = a; j = b; } complex operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; } void show(){ cout<<"Complex Number: "<<i<<" + i"<<j<<endl; } }; int main(int argc, char const *argv[]) { complex c1(1,2); complex c2(3,4); complex c3 = c1 + c2; c3.show(); return 0; }
Q10
How many types are there in increment/decrement operator?
Q11
What is the purpose of using the 'explicit' keyword in front of a constructor declaration in C++?
Q12
In C++, what is the purpose of the 'this' pointer in a class member function?
Q13
Which keyword is used to prevent inheritance in C++?
Q14
What will be the output of the following C++ code? #include <iostream> using namespace std; class Rect { int x, y; public: void set_values (int,int); int area () { return (x * y); } }; void Rect::set_values (int a, int b) { x = a; y = b; } int main () { Rect recta, rectb; recta.set_values (5, 6); rectb.set_values (7, 6); cout << "recta area: " << recta.area(); cout << "rectb area: " << rectb.area(); return 0; }
Q15
What is the process of hiding the implementation details of a class and showing only the necessary features to the outside world called in C++?
Q16
How to unlimit the size of the stack?
Q17
In C++, what is the difference between a shallow copy and a deep copy?
Q18
What is the purpose of the 'static' keyword in C++ class members?
Q19
Which keyword is used to prevent a class from being inherited in C++?
Q20
Which access specifier allows constructors to be called from anywhere in the program in C++?
Q21
What will be the output of the following C++ code? #include <iostream> using namespace std; class sample; class sample1 { int width, height; public: int area () { return (width * height);} void convert (sample a); }; class sample { private: int side; public: void set_side (int a) { side = a; } friend class sample1; }; void sample1::convert (sample a) { width = a.side; height = a.side; } int main () { sample sqr; sample1 rect; sqr.set_side(6); rect.convert(sqr); cout << rect.area(); return 0; }
Q22
What happens if a class does not explicitly declare any constructors in C++?
Q23
Which operator is having the highest precedence in c++?
Q24
What is the purpose of a destructor in C++?
Q25
What is the difference between a shallow copy and a deep copy in C++?