What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class complex{
double re, im;
public:
complex() : re(1),im(0.3) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
complex operator+(complex &t);
void Print() { cout << re << " " << im; }
};
complex complex::operator+ (complex &t){
complex temp;
temp.re = this?>re + t.re;
temp.im = this?>im + t.im;
return temp;
}
int main(){
complex c1(1),c2(2),c3;
c3 = c1 + c2;
c3.Print();
}
Answer : C
What will the variable "y" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
};
class B : private A {
string name;
public:
void Print() {
cout << name << age;
}
};
Answer : B
If there is one, point out an error in the program
#include
using namespace std;
int main()
{
int i=1;
for(;;)
{
cout<
if(i>5)
break;
}
return 0;
}
Answer : C
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int op(int x, int y);
float op(int x, float y);
int main()
{
int i=1, j=2, k;
float f=0.3;
k = op(i, j);
cout<< k << "," << op(0, f);
return 0;
}
int op(int x, int y)
{
return x+y;
}
float op(int x, float y)
{
return x?y;
}
Answer : B
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main(){
int i = 1;
if (--i==1) {
cout << i;
} else {
cout << i-1;
}
return 0;
}
Answer : C
What will happen when you attempt to compile and run the following code?
#include
#include
using namespace std;
int fun(int);
int main()
{
int *x = new int;
*x=10;
cout << fun(*x);
return 0;
}
int fun(int i)
{
return i*i;
}
Answer : A
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int fun(int x);
int main() {
cout << fun(0);
return 0;
}
int fun(int x) {
if(x > 0)
return fun(x-1);
else
return 100;
}
Answer : C