41. Which of the following operator cannot be overloaded?
42. Pick the correct statement.
43. Which is used to define the member of a class externally?
44. 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;
}
#include <iostream>
using namespace std;
ostream & operator<<(ostream & i, int n)
{
return i;
}
int main()
{
cout << 5 << endl;
cin.get();
return 0;
}
45. 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;
}
#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;
}
46. Which operator a pointer object of a class uses to access its data members and member functions?
47. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a:";
cout << a;
cout << " b:";
cout << b;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a:";
cout << a;
cout << " b:";
cout << b;
return 0;
}
48. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
std::string str ("Example.");
str.back() = '!';
std::cout << str << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main ()
{
std::string str ("Example.");
str.back() = '!';
std::cout << str << endl;
return 0;
}
49. Which is the correct example of a unary operator?
50. In case of non-static member functions how many maximum object arguments a binary operator overloaded function can take?
Read More Section(Classes and Objects in C plus plus)
Each Section contains maximum 100 MCQs question on Classes and Objects in C plus plus. To get more questions visit other sections.