81. Which of the following is not a modifier function in string class?
82. In the case of friend operator overloaded functions how many maximum object arguments a unary operator overloaded function can take?
83. What will be the output of the following C++ code?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<int> i(2, 3);
i = i * 6 / 3;
cout << i;
return 0;
}
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<int> i(2, 3);
i = i * 6 / 3;
cout << i;
return 0;
}84. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class sample
{
public:
sample()
{
cout << "X::X()" << endl;
}
sample( sample const & )
{
cout << "X::X( X const & )" << endl;
}
sample& operator=( sample const & )
{
cout << "X::operator=(X const &)" << endl;
}
};
sample f()
{
sample tmp;
return tmp;
}
int main()
{
sample x = f();
return 0;
}
#include <iostream>
using namespace std;
class sample
{
public:
sample()
{
cout << "X::X()" << endl;
}
sample( sample const & )
{
cout << "X::X( X const & )" << endl;
}
sample& operator=( sample const & )
{
cout << "X::operator=(X const &)" << endl;
}
};
sample f()
{
sample tmp;
return tmp;
}
int main()
{
sample x = f();
return 0;
}85. Which of the following operators can't be overloaded?
86. Which of the following statements is NOT valid about operator overloading?
87. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}88. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Distance
{
private:
int feet;
int inches;
public:
Distance()
{
feet = 0;
inches = 0;
}
Distance(int f, int i)
{
feet = f;
inches = i;
}
Distance operator()(int a, int b, int c)
{
Distance D;
D.feet = a + c + 10;
D.inches = b + c + 100 ;
return D;
}
void displayDistance()
{
cout << feet << inches << endl;
}
};
int main()
{
Distance D1(11, 10), D2;
cout << "First Distance : ";
D1.displayDistance();
D2 = D1(10, 10, 10);
cout << "Second Distance :";
D2.displayDistance();
return 0;
}
#include <iostream>
using namespace std;
class Distance
{
private:
int feet;
int inches;
public:
Distance()
{
feet = 0;
inches = 0;
}
Distance(int f, int i)
{
feet = f;
inches = i;
}
Distance operator()(int a, int b, int c)
{
Distance D;
D.feet = a + c + 10;
D.inches = b + c + 100 ;
return D;
}
void displayDistance()
{
cout << feet << inches << endl;
}
};
int main()
{
Distance D1(11, 10), D2;
cout << "First Distance : ";
D1.displayDistance();
D2 = D1(10, 10, 10);
cout << "Second Distance :";
D2.displayDistance();
return 0;
}89. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
int a = 5;
public:
void change(int i){
a = i;
}
static void value_of_a(){
cout<<a;
}
};
int main(int argc, char const *argv[])
{
A a1 = A();
a1.change(10);
a1.value_of_a();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class A
{
int a = 5;
public:
void change(int i){
a = i;
}
static void value_of_a(){
cout<<a;
}
};
int main(int argc, char const *argv[])
{
A a1 = A();
a1.change(10);
a1.value_of_a();
return 0;
}90. Where does the object is created?
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.
