Classes And Objects In C Plus Plus - Study Mode
[#226] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
static int a
public:
void show()
{
a++
cout<<"a: "<<a<<endl
}
}
int A::a = 5
int main(int argc, char const *argv[])
{
A a
return 0
}
Correct Answer
(C) No output
[#227] Which operator should be overloaded in the following code to make the program error free? #include <iostream>
#include <string>
using namespace std
class Box{
int capacity
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<<"Equal"
}
else{
cout<<"Not Equal"
}
return 0
}
Correct Answer
(B) ==
[#228] Which of the following is a valid class declaration?
Correct Answer
(A) class A { int x
}
[#229] What will be the output of the following C++ code? #include <iostream>
#include <complex>
using namespace std
int main()
{
complex<double> c1(4.0, 16.0), c2
c2 = pow(c1, 2.0)
cout << c2
return 0
}
Correct Answer
(A) (-240, 128)
[#230] What will be the output of the following C++ code? #include <iostream>
using namespace std
class S
{
int m
public:
#define MAC(S::m)
}
int main(int argc, char const *argv[])
{
cout<<"Hello World"
return 0
}
Correct Answer
(B) Error