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.
What is the output of the program given below?
#include
using namespace std;
int main (int argc, const char * argv[])
{
int i=10;
{
int i=0;
cout<
}
cout<
return 0;
}
A. 1010
B. 100
C. 010
D. None of these
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main(){
int i, j;
for(i = 0, j = 1; j < 2, i < 4; i++, j++);
cout << i << " " << j;
return 0;
}
A. It prints: 4 5
B. It prints: 2 3
C. It prints: 3 2
D. It prints: 4 3
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class First
{
public:
void Print(){ cout<<"from First";}
};
class Second
{
public:
void Print(){ cout<< "from Second";}
};
int main()
{
First FirstObject;
FirstObject.Print();
Second SecondObject;
SecondObject.Print();
}
A. It prints: from First
B. It prints: from Firstfrom First
C. It prints: from Firstfrom Second
D. It prints: from Secondfrom Second
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int fun(int x);
int main() {
cout << fun(0);
}
int fun(int x) {
if(x > 0)
return fun(x-1);
else
return 100;
}
A. It prints: 0
B. It prints: 10
C. It prints: 100
D. It prints: -1
What will happen when you attempt to compile and run the following code?
#include
using namespace std;
int main (int argc, const char * argv[])
{
enum state { ok, error, warning};
enum state s1, s2, s3;
s1 = ok;
s2 = warning;
s3 = error;
s4 = ok;
cout << s1<< s2<< s3;
return 0;
}
A. It will print:"123"
B. compilation error
C. It will print:"021"
D. It will print:"132"
Which code line instead of the comment below will cause the program to produce the expected output?

A. a = b * c;
B. return a = b * c;
C. return a = b * *c;
D. a = b * *c;
What happens when you attempt to compile and run the following code?

A. It prints: T
B. It prints an empty line
C. It prints: Tesc
D. It prints: st
What is the output of the program?
#include
#include
using namespace std;
struct t
{
int tab[2];
};
class First
{
struct t u;
public:
First() {
u.tab[0] = 1;
u.tab[1] = 0;
}
void Print(){
cout << u.tab[0] << " " << u.tab[1];
}
};
int main()
{
First t;
t.Print();
}
A. It prints: 2 2
B. It prints: 1 1
C. It prints: 1 0
D. It prints: 0 0
Which of the following structures are correct?
1: struct s1{ int x; char c; };
2: struct s2{ float f; struct s2 *s; };
3: struct s3{
float f;
in i;
}
A. 1
B. 2
C. 3
D. All of these