What is the output of the program?
#include
#include
using namespace std;
union t
{
char c;
int i;
};
class First
{
union t u;
public:
First() {
u.c = 'A';
}
void Print(){
cout << u.c;
}
};
int main()
{
First *t = new First();
t?>Print();
}
Answer : B
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class A
{
public:
virtual 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();
}
Answer : A
What is not inherited from the base class?
Answer : A, B, C
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int x=5;
static int y=0;
void myFunction(int a)
{
y=++a;
}
int main (int argc, const char * argv[])
{
int i=0;
myFunction(i);
cout< }
Answer : C
What is the output of the program given below?
#include
using namespace std;
int main (int argc, const char * argv[])
{
float f=?10.501;
cout<<(int)f;
}
Answer : C
Which of the structures is incorrect?
1:
struct s1{
int x;
long int li;
};
2:
struct s2{
float f;
struct s2 *s;
};
3:
struct s3{
float f;
struct s3 s;
};
Answer : C
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
const int size = 3;
class A {
public:
string name;
A() { name = "Bob";}
A(string s) { name = s;}
A(A &a) { name = a.name;}
};
class B : public A {
public:
B() { }
B(string s) : A(s) { }
void Print() {
cout << name;
}
};
int main () {
B b1("Alan");
b1.Print();
return 0;
}
Answer : C