What is the expected output of the following program?
Answer : B
Which code, inserted at line 8, generates the output "100"?
#include
using namespace std;
int fun(int);
int main()
{
int *x = new int;
*x=10;
//insert code here
return 0;
}
int fun(int i)
{
return i*i;
}
Answer : A, B
Which definitions are correct?
Answer : A, C
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int a=5;
cout << ((a < 5) ? 9.9 : 9);
}
Answer : A
Which code, inserted at line 18, generates the output "AB"
#include
using namespace std;
class A
{
public:
void Print(){ cout<< "A";}
void Print2(){ cout<< "a";}
};
class B:public A
{
public:
void Print(){ cout<< "B";}
void Print2(){ cout<< "b";}
};
int main()
{
B ob2;
//insert code here
ob2.Print();
}
Answer : D
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class A {
protected:
int y;
public:
int x, z;
A() : x(1), y(2), z(0) {}
A(int a, int b) : x(a), y(b) { z = x * y;}
void Print() { cout << z; }
};
class B : public A {
public:
int y;
B() : A() {}
B(int a, int b) : A(a,b) {}
void Print() { cout << z; }
};
int main () {
A b(2,5);
b.Print();
return 0;
}
Answer : A
What is the output of the program?
#include
using namespace std;
#define PRINT(i) cout<
int main()
{
int y=2, z=3;
PRINT(y);
PRINT(z);
return 0;
}
Answer : B