41. What will be the output of the following C++ code?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<double> c1(4.0,3.0);
cout << "c1: " << c1;
complex<float> c2(polar(5.0,0.75));
cout << c1 + complex<double>(c2.real(),c2.imag());
return 0;
}
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<double> c1(4.0,3.0);
cout << "c1: " << c1;
complex<float> c2(polar(5.0,0.75));
cout << c1 + complex<double>(c2.real(),c2.imag());
return 0;
}42. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int x;
int *p;
x = 5;
p = &x;
cout << *p;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int x;
int *p;
x = 5;
p = &x;
cout << *p;
return 0;
}43. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int i;
enum month
{
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC
};
for (i = JAN; i <= DEC; i++)
cout << i;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int i;
enum month
{
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC
};
for (i = JAN; i <= DEC; i++)
cout << i;
return 0;
}44. How many approaches are used for operator overloading?
45. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int a, b;
int* c;
c = &a;
a = 200;
b = 200;
*c = 100;
b = *c;
cout << *c << " " << b;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int a, b;
int* c;
c = &a;
a = 200;
b = 200;
*c = 100;
b = *c;
cout << *c << " " << b;
return 0;
}46. Pick out the correct statement.
47. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
static int a;
public:
void change(int i){
a = i;
}
void value_of_a(){
cout<<a;
}
};
int main(int argc, char const *argv[])
{
A a1 = A();
a1.change(5);
a1.value_of_a();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class A
{
static int a;
public:
void change(int i){
a = i;
}
void value_of_a(){
cout<<a;
}
};
int main(int argc, char const *argv[])
{
A a1 = A();
a1.change(5);
a1.value_of_a();
return 0;
}48. What is the syntax of overloading operator + for class A?
49. What will be the output of the following C++ code if the string entered by the user is "Hello World"?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
string str;
cin>>str;
cout<<str;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
string str;
cin>>str;
cout<<str;
return 0;
}50. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
double a = 21.09399;
float b = 10.20;
int c ;
c = (int) a;
cout << c ;
c = (int) b;
cout << c ;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
double a = 21.09399;
float b = 10.20;
int c ;
c = (int) a;
cout << c ;
c = (int) b;
cout << c ;
return 0;
}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.
