What happens when you attempt to compile and run the following code?
#include
using namespace std;
class BaseClass
{
public:
int *ptr;
BaseClass(int i) { ptr = new int(i); }
~BaseClass() { delete ptr; delete ptr;}
void Print() { cout << *ptr; }
};
void fun(BaseClass x);
int main()
{
BaseClass o(10);
fun(o);
o.Print();
}
void fun(BaseClass x) {
cout << "Hello:";
}
A. It prints: Hello:1
B. It prints: Hello:
C. It prints: 10
D. Runtime error.
Which statement should be added in the following program to make work it correctly?
using namespace std;
int main (int argc, const char * argv[])
{
cout<<"Hello";
}
A. #include
B. #include
C. #include
D. #include
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
const int x=0;
const int *ptr;
ptr = andx;
cout<<*ptr;
return 0;
}
A. It prints: 0
B. It prints address of x
C. It prints: 1
D. Compilation error
What happens when you attempt to compile and run the following code?
#include
using namespace std;
namespace myNamespace1
{
int x = 5;
int y = 10;
}
namespace myNamespace2
{
float x = 3.14;
float y = 1.5;
}
int main () {
{
using namespace myNamespace1;
cout << x << " ";
}{
using namespace myNamespace2;
cout << y;
}
return 0;
}
A. It prints: 5 1.5
B. It prints: 3.14 10
C. Compilation error
D. None of these
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;
}
A. It prints: 3,1
B. It prints: 3,?0.3
C. It prints: 3,0
D. It prints: 0,0
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class A {
public:
void Print(){ cout<<"A";}
};
class B:public A {
public:
virtual void Print(){ cout<< "B";}
};
class C:public B {
public:
void Print(){ cout<< "C";}
};
int main()
{
A ob1;
B ob2;
C ob3;
B *obj;
obj = andob2;
obj?>Print();
obj = andob3;
obj?>Print();
}
A. It prints: BB
B. It prints: AA
C. It prints: BC
D. It prints: AB
Which line of code inserted instead of the comment will make the following code run properly without causing memory leaks?

A. ~Base() ( delete this; }
B. no additional code is needed
C. ~Base() { delete ptr; delete ptr; }
D. ~Base() { delete ptr; }
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int op(int x, int y);
int main()
{
int i=2, j=2, k;
float f=0.3;
k = op(i, j);
cout<< k << "," << op(1, f);
return 0;
}
int op(int x, int y)
{
return x+y;
}
A. It prints: 4,1
B. It prints: 4,0.7
C. It prints: 4,0
D. It prints: 0,4
If there is one, point out an error in the program
#include
using namespace std;
int main()
{
int c = 'a';
switch(i)
{
case '2':
cout<<"OK";
case '1':
cout<<"Error";
default:
break;
}
return 0;
}
A. No Error
B. Use of undeclared identifier 'i'
C. Illegal use of 'continue'
D. Illegal use of 'break'
What happens when you attempt to compile and run the following code?

A. It causes a compilation error
B. It prints: Tesc failed
C. .It prints: failed
D. It prints: Tesc