Question 71
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class Base
{
string s;
public:
Base() { s="Sample text";}
Base(string s) { this->s=s; }
void Print() { cout << s; }
};
int main()
{
Base *o = new Base();
o->Print();
}
Question 72
What happens when you attempt to compile and run the following code?
#include <iostream> #include <string> using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
};
class B : private A {
string name;
public:
void set() {
x = 1;
}
void Print() {
cout << x;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
Question 73
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int x=0;
int *ptr;
ptr = &x;
cout<<x<<" "<<*ptr;
return 0;
}
Question 74
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
const int x=20;
const int *ptr;
ptr = &x;
*ptr = 10;
cout<<*ptr;
return 0;
}
Question 75
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A
{
public:
void Print(){ cout<<"A";}
};
class B:public A
{
public:
virtual void Print(){ cout<< "B";}
};
int main()
{
A *obj;
A ob1;
obj = &ob1;
obj?>Print();
B ob2;
obj = &ob2;
obj?>Print();
}
