Question 1 of 25
Hints left: 3
Q1
What is the purpose of the keyword 'explicit' before a constructor in C++?
Q2
Which is used to define the member of a class externally?
Q3
What is operator overloading in C++?
Q4
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class Box{ int capacity; bool operator<(Box b){ return this->capacity < b.capacity ? true : false; } public: Box(){} Box(double capacity){ this->capacity = capacity; } }; int main(int argc, char const *argv[]) { Box b1(10); Box b2 = Box(14); if(b1 < b2){ cout<<"Box 2 has large capacity."; } else{ cout<<"Box 1 has large capacity."; } return 0; }
Q5
How many parameters does a conversion operator may take?
Q6
What will be the output of the following C++ code? #include <iostream> using namespace std; ostream & operator<<(ostream & i, int n) { return i; } int main() { cout << 5 << endl; cin.get(); return 0; }
Q7
Which keyword is used to create a copy constructor in C++?
Q8
What is a constructor in C++?
Q9
What is the difference between a constructor and a normal member function in C++?
Q10
What happens if a class does not explicitly declare any constructors in C++?
Q11
Which access specifier allows members of a class to be accessed only by member functions of the same class and its derived classes in C++?
Q12
What is the purpose of using constructors in C++?
Q13
What is the term for a function that is declared inside a class but defined outside of it in C++?
Q14
Pick the correct statement.
Q15
What is the purpose of a copy constructor in C++?
Q16
Which keyword is used to prevent inheritance in C++?
Q17
What will be the output of the following C++ code? #include <iostream> using namespace std; class Integer { int i; public: Integer(int ii) : i(ii) {} const Integer operator+(const Integer& rv) const { cout << "operator+" << endl; return Integer(i + rv.i); } Integer& operator+=(const Integer& rv) { cout << "operator+=" << endl; i += rv.i; return *this; } }; int main() { int i = 1, j = 2, k = 3; k += i + j; Integer ii(1), jj(2), kk(3); kk += ii + jj; }
Q18
Which keyword is used to make a member function constant in C++?
Q19
Which of the following operator cannot be overloaded?
Q20
What is the access specifier that allows members of a class to be accessed from anywhere in the program in C++?
Q21
What is a destructor in C++?
Q22
What is the difference between a shallow copy and a deep copy in C++?
Q23
What is the purpose of the 'this' pointer in C++?
Q24
What is the process of wrapping data and functions into a single unit called in C++?
Q25
What will be the output of the following C++ code? #include <iostream> #include <complex> using namespace std; int main () { complex<double> mycomplex (20.0, 2.0); cout << imag(mycomplex) << endl; return 0; }