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 : public A {
string name;
public:
void set() {
y = 2;
z = 3;
}
void Print() { cout < < y < < z; }
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
class A {
public:
int x;
A() { x=0;}
};
class B : public A {
public:
B() { x=1;}
};
class C : private B {
public:
C() { x=2;}
};
int main () {
C c1;
cout < < c1.x;
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main()
{
int x=20;
int *ptr;
ptr = & x;
cout < < *ptr;
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
struct {
int x;
char c;
union {
float f;
int i;
};
} s;
int main (int argc, const char * argv[])
{
s.x=10;
s.i=0;
cout < < s.i < < " " < < s.x;
}
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;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < string >
using namespace std;
class First
{
string *s;
public:
First() { s = new string( " Text " );}
~First() { delete s;}
void Print(){ cout < < *s;}
};
int main()
{
First FirstObject;
FirstObject.Print();
FirstObject.~First();
}
What is the output of the program if character 4 is supplied as input?
#include < iostream >
using namespace std;
int main () {
int c;
cin > > c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw ' a ' ;
default:
cout < < " No exception " ;
}
}
catch (int e)
{ cout < < " int exception. Exception Nr. " < < e; }
catch (float e)
{ cout < < " float exception. Exception Nr. " < < e; }
catch (...)
{ cout < < " An exception occurred. " ; }
return 0;
}
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 :
void print() {
cout < < " B " ;
}
};
int main() {
B sc[2];
B *bc = (B*)sc;
for (int i=0; i < 2;i++)
(bc++)- > print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
class First
{
public:
void Print(){ cout < < " from First " ;}
};
class Second
{
public:
void Print(){ cout < < " from Second " ;}
};
int main()
{
Second t[2];
for (int i=0; i < 2; i++)
t[i].Print();
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < string >
using namespace std;
void fun(int i);
int main()
{
int i=0;
i++;
for (i=0; i < =5; i++)
{
fun(i);
}
return 0;
}
void fun(int i)
{
if (i==3)
return;
cout < < i;
}
What happens when you attempt to compile and run the following code?
#include < cstdlib >
#include < iostream >
using namespace std;
float* sum(float a,float b);
float* sum(float a,float b)
{
float *f = new float;
*f = a+b;
return f;
}
int main()
{
float a,b,*f;
a = 1.5; b = 3.4;
f = sum(a,b);
cout < < *f;
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int compare(int, int);
int main()
{
int x = compare(10, 20);
cout < < x;
return 0;
}
int compare(int i, int j)
{
return i < j;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < string >
using namespace std;
int main()
{
string s1[]= { " How " , " to " };
s1[0].swap(s1[1] );
for (int i=0; i < 2; i++) {
cout < < s1[i];
}
return( 0 );
}
Which code line instead of the comment below will cause the program to produce the expected output?

Which code line inserted instead of the comment below will cause the program to produce the expected output?

What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main()
{
int *a= new int;
*a=100;
cout < < *a;
delete a;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main(){
int i = 1;
if (i==1) {
cout < < i;
} else {
cout < < i-1;
}
return 0;
}
What will the variable " y " be in class B?
class A {
int x;
protected:
int y;
public:
int age;
};
class B : private A {
string name;
public:
void Print() {
cout < < name < < age;
}
};
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
void set(struct person*);
struct person
{
int age;
};
int main()
{
struct person e = {18};
set( & e);
cout < < e.age;
return 0;
}
void set(struct person *p)
{
p? > age = p? > age + 1;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < cstdarg >
using namespace std;
int mult(int f, int s, int t);
int main()
{
cout < < mult(1,2,3);
return 0;
}
int mult(int f, int s, int t)
{
int mult_res;
mult_res = f*s*t;
return mult_res;
}
Which code, inserted at line 10, generates the output " Hello World " ?
#include < iostream >
#include < string >
using namespace std;
string fun(string, string);
int main()
{
string s= " Hello " ;
string *ps;
ps = & s;
//insert code here
return 0;
}
string fun(string s1, string s2)
{
return s1+s2;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main()
{
int x=2, *y;
y = & x;
cout < < *y + x;
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
void fun(int*);
int main()
{
int i=2;
fun( & i);
cout < < i;
return 0;
}
void fun(int *i)
{
*i = *i**i;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main (int argc, const char * argv[])
{
int a = 30, b = 1, c = 5, i=10;
i = b < a < c;
cout < < i;
return 0;
}
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;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
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;
}
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();
}
How many copies of the value member are stored in memory during program execution?

What happens when you attempt to compile and run the following code?
#include < iostream >
#include < string >
using namespace std;
class Second;
class Base {
int age;
public:
Base () { age=5; };
friend void set(Base & ob, Second & so);
void Print() { cout < < age;}
};
class Second {
string name;
public:
friend void set(Base & ob, Second & so);
void Print() { cout < < name;}
};
void set(Base & ob, Second & so) {
ob.age = 0; so.name = " Bill " ;
}
int main () {
Base a;
Second b;
set(a,b);
a.Print();
b.Print();
return 0;
}
If there is one, point out an error in the program
#include < iostream >
using namespace std;
int main()
{
int c = ' a ' ;
switch(i)
{
case ' 2 ' :
cout < < " OK " ;
case ' 1 ' :
cout < < " Error " ;
default:
break;
}
return 0;
}
Which code, inserted at line 19, generates the output " 23 " ?
#include < iostream >
#include < string >
using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
A() { x=1; y=2; z=3; }
};
class B : public A {
string z;
public:
int y;
void set() { y = 4; z = " John " ; }
void Print() {
//insert code here
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < string >
using namespace std;
class SampleClass
{
string *s;
public:
SampleClass() { s = new string( " Text " );}
SampleClass(string s) { this? > s = new string(s);}
~SampleClass() { delete s;}
void Print(){ cout < < *s;}
};
int main()
{
SampleClass *obj;
obj = new SampleClass( " Test " );
obj? > Print();
}
What is the output of the program given below?
#include < iostream >
using namespace std;
int main (int argc, const char * argv[])
{
float f=?10.501;
cout < < (int)f;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
class A {
public:
virtual void Print()=0;
};
class B:public A {
public:
virtual void Print() { cout < < " B " ; }
};
class C:public A {
public:
virtual void Print() { cout < < " C " ; }
};
int main()
{
B ob2;
C ob3;
A *obj;
obj = & ob2;
obj? > Print();
obj = & ob3;
obj? > Print();
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < string >
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;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int mul (int a, int b=2)
{
int r;
r=a*b;
return (r);
}
int main ()
{
cout < < mul(1) < < mul(2,4);
return 0;
}
What is the output of the program if character “1” is supplied as input?
#include < iostream >
using namespace std;
int main () {
int c;
cin > > c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw ' a ' ;
}
}
catch (int e)
{ cout < < " int exception. Exception Nr. " < < e; }
catch (float e)
{ cout < < " float exception. Exception Nr. " < < e; }
catch (...)
{ cout < < " An exception occurred. " ; }
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
void set(struct person*);
struct person
{
char name[25];
int age;
};
int main()
{
struct person e = { " Steve " , 30};
set( & e);
cout < < e.name < < " " < < e.age;
return 0;
}
void set(struct person *p)
{
p? > age = p? > age + 1;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main() {
int i, j;
for(i = 0; i < 2; i++) {
for(j = i; j < i + 1; j++)
if(j == i)
continue;
else
break;
}
cout < < j;
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
class First
{
public:
virtual void Print(){ cout < < " from First " ;}
};
class Second:public First
{
public:
void Print(){ cout < < " from Second " ;}
};
void fun(First *obj);
int main()
{
First FirstObject;
fun( & FirstObject);
Second SecondObject;
fun( & SecondObject);
}
void fun(First *obj)
{
obj? > Print();
}
What is the output of the program given below?
#include < iostream >
using namespace std;
int main (int argc, const char * argv[])
{
int i=10;
{
int i=0;
cout < < i;
}
{
int i=5;
cout < < i;
}
cout < < i;
return 0;
}
What is the output of the program if characters ' t ' , ' e ' , ' s ' and ' t ' enter are supplied as input?
#include < iostream >
#include < string >
using namespace std;
int main()
{
string s;
getline( cin, s );
cout < < s < < " " < < s.length();
return( 0 );
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main()
{
int x=2, *y, z=3;
y = & z;
cout < < x**y*x***y;
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main(){
int i = 1;
if (--i==1) {
cout < < i;
} else {
cout < < i-1;
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
void fun(int);
int main()
{
int a=0;
fun(a);
return 0;
}
void fun(int n)
{
if(n < 2)
{
fun(++n);
cout < < n;
}
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int fun(int x) {
return x < < 2;
}
int main(){
int i;
i = fun(1) / 2;
cout < < i;
return 0;
}
What will happen when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int getValue();
int main()
{
const int x = getValue();
cout < < x;
return 0;
}
int getValue()
{
return 5;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
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 < < y < < " " < < x;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main()
{
int i=2;
switch(i)
{
case 1:
cout < < " Hello " ;
case 2:
cout < < " world " ;
case 3:
cout < < " End " ;
} return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < string >
using namespace std;
class A {
protected:
int y;
public:
int x,z;
A() : x(1), y(2), z(0) { z = x + y; }
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;
b.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main(){
int i, j;
for(i = 0, j = 1; j < 2, i < 4; i++, j++);
cout < < i < < " " < < j;
return 0;
}
What is the output of the program?
#include < iostream >
#include < string >
using namespace std;
int main()
{
string s1= " Hello " ;
string s2= " World " ;
s1+=s2;
cout < < s1;
return( 0 );
}
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 :
void print() {
cout < < " B " ;
}
};
int main() {
B sc[2];
A *bc = (A*)sc;
for (int i=0; i < 2;i++)
(bc++)- > print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
void fun(int*);
int main()
{
int *x;
int i=2;
x= & i;
fun(x);
cout < < i;
return 0;
}
void fun(int *i)
{
*i = *i * *i;
}
What is the output of the program?
#include < iostream >
using namespace std;
#define PRINT(i) cout < < i;
int main()
{
int y=2, z=3;
PRINT(y);
PRINT(z);
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < string >
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:
int *tab;
B() { tab = new int[size]; for (int i=0; i < size; i++) tab[i]=1;}
B(string s) : A(s) { tab = new int[size]; for (int i=0; i < size; i++) tab[i]=1;}
~B() { delete tab; }
void Print() {
for (int i=0; i < size; i++) cout < < tab[i];
cout < < name;
}
};
int main () {
B b1( " Alan " );
B b2;
b1.tab[0]=0;
b1.Print(); b2.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main()
{
int i = 4;
while(i > = 0) {
cout < < i;
i??;
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
class A {
public:
int x;
A() { x=0;}
};
class B : protected A {
public:
int y;
using A::x;
B(int y) {this? > y = y;}
void Print() { cout < < x < < y; }
};
int main () {
B b(5);
b.Print();
return 0;
}
What is the output of the program?
#include < iostream >
#include < string >
using namespace std;
int main()
{
string s1[]= { " H " , " t " };
string s;
for (int i=0; i < 2; i++) {
s = s1[i];
if (i==0)
s.insert(1, " ow " );
else
s.push_back( ' o ' );
cout < < s;
}
return( 0 );
}
What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int op(int x, int y)
{
return x?y;
}
int op(int x, float y)
{
return x+y;
}
int main()
{
int i=1, j=2, k, l;
float f=0.23;
k = op(i, j);
l = op(j, f);
cout < < k < < " , " < < l;
return 0;
}
Which line of code inserted instead of the comment will make the following code run properly without causing memory leaks?

What happens when you attempt to compile and run the following code?
#include < iostream >
using namespace std;
int main()
{
int x,y=10;
float f;
f = 5.90;
cout < < f < < " , " ;
x=f;
cout < < x < < " , " ;
f=y;
cout < < f;
return 0;
}
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;
}