What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
int x;
};
class B : public A {
public:
B() { x=1;}
B(int x) {this?>x = x;}
};
int main () {
B c1;
B c2(10);
cout << c1.x;
cout << c2.x;
return 0;
}
Answer : B
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void fun(char*);
int main()
{
char t[4]={'0', '1', '2', '3'};
fun(&t[2]);
return 0;
}
void fun(char *a)
{
cout << *a;
}
Answer : A
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
A() { cout << "A no parameters";}
A(string s) { cout << "A string parameter";}
A(A &a) { cout << "A object A parameter";}
};
class B : public A {
public:
B() { cout << "B no parameters";}
B(string s) { cout << "B string parameter";}
};
int main () {
A a2("Test");
B b1("Alan");
B b2(b1);
return 0;
}
Answer : B
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
string s;
A(string s) { this?>s = s; }
};
class B {
public:
string s;
B (A a) { this?>s = a.s; }
void print() { cout<<s; }
};
int main()
{
A a("Hello world");
B b=a;
b.print();
}
Answer : A
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int op(int x, int y);
int main()
{
float *pf;
float f=0.9;
pf=&f;
cout << op(1, *pf);
return 0;
}
int op(int x, int y)
{
return x*y;
}
Answer : A
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class First
{
string *s;
public:
First() { s = new string("Text");}
~First() { delete s;}
void Print(){ cout<<*s;}
};
int main()
{
First FirstObject;
FirstObject.Print();
FirstObject.~First();
}
Answer : C
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A
{
public:
virtual void Print(){ cout<<"A";}
};
class B:public A
{
public:
void Print(){ cout<< "B";}
};
int main()
{
A *obj;
A ob1;
obj = &ob1;
obj?>Print();
B ob2;
obj = &ob2;
obj?>Print();
}
Answer : A
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(void)
{
string s;
s = "Test";
s.resize (s.size() ? 1);
cout<<s<<" "<<s.size();
return 0;
}
Answer : D
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A {
public:
int x;
A() { x=0;}
};
class B : public A {
public:
B() { x=1;}
};
class C : private B {
public:
C() { x=2;}
};
int main () {
C c1;
cout << c1.x;
return 0;
}
Answer : D
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
A() { cout << "A no parameters";}
A(string s) { cout << "A string parameter";}
A(A &a) { cout << "A object A parameter";}
};
class B : public A {
public:
B() { cout << "B no parameters";}
B(string s) { cout << "B string parameter";}
B(int s) { cout << "B int parameter";}
};
int main () {
A a2("Test");
B b1(10);
B b2(b1);
return 0;
}
Answer : B
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
class First
{
public:
void Print(){ cout<<"from First";}
};
int main()
{
First t[2];
for (int i=0; i<2; i++)
t[i].Print();
}
Answer : B
What is the output of the program given below?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int i=10;
{
int i=0;
cout<<i;
}
cout<<i;
return 0;
}
Answer : C
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
int x;
A() { x=0;}
A(int x) { this?>x=x;}
};
class B : private A {
public:
using A::x;
B() { x=1;}
B(int x) {this?>x = x;}
};
int main () {
B c1;
B c2(?5);
cout << c1.x;
cout << c2.x;
return 0;
}
Answer : B
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int a = 30, b = 1, c = 5, i=10;
i = b < a < c;
cout << i;
return 0;
}
Answer : D
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class B;
class A {
int age;
public:
A () { age=5; };
friend class B;
};
class B {
string name;
public:
B () { name="Bob"; };
void Print(A ob) {
cout << name << ob.age;
}
};
int main () {
A a;
B b;
b.Print(a);
return 0;
}
Answer : A
Have any questions or issues ? Please dont hesitate to contact us