Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class numbers    {        private:        int m_nValues[10];        public:        int& operator[] (const int nValue);    };    int& numbers::operator[](const int nValue)    {        return m_nValues[nValue];    }    int main()    {        numbers N;        N[5] = 4;        cout <<  N[5];        return 0;    }

Choices:
- 5
- 4
- 3
- 6


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    const int limit = 4;    class safearray    {        private:        int arr[limit];        public:        int& operator [](int n)        {            if (n == limit - 1)            {                int temp;                for (int i = 0; i < limit; i++)                {                    if (arr[n + 1] > arr[n])                    {                        temp = arr[n];                        arr[n] = arr[n + 1];                        arr[n + 1] = temp;                    }                     }              }            return arr[n];        }    };    int main()    {        safearray sa1;        for(int j = 0; j < limit; j++)            sa1[j] = j*10;        for(int j = 0; j < limit; j++)        {            int temp = sa1[j];            cout << "Element " << j << " is " << temp;        }        return 0;    }

Choices:
- 0102030
- 1020300
- 3020100
- error


Question:
What will be the output of the following C++ code?
    #include <iostream>     using namespace std;    class A    {        public:        int x;        A(int n = 0) : x(n) {};        int& operator[](int n)        {             cout << "0" ;             return x;        }        int operator[](int n) const        {             cout << "1" ;             return x;        }     };    void foo(const A& a)    {        int z = a[2];    }    int main()    {        A a(7);        a[3]  = 8;        int z = a[2];        foo(a);        return 0;    }

Choices:
- 110
- 111
- 011
- 001


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class sample    {        private:        int* i;        int j;        public:        sample (int j);        ~sample ();        int& operator [] (int n);    };    int& sample::operator [] (int n)    {        return i[n];    }    sample::sample (int j)    {        i = new int [j];        j = j;    }    sample::~sample ()    {        delete [] i;    }    int main ()    {        sample m (5);        m [0] = 25;        m [1] = 20;        m [2] = 15;        m [3] = 10;        m [4] = 5;        for (int n = 0; n < 5; ++ n)        cout << m [n];        return 0;    }

Choices:
- 252015105
- 510152025
- 51015
- 51015210


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    void duplicate (int& a, int& b, int& c)    {        a *= 2;        b *= 2;        c *= 2;    }    int main ()    {        int x = 1, y = 3, z = 7;        duplicate (x, y, z);        cout << x << y << z;        return 0;    }

Choices:
- 1468
- 2812
- 2614
- 2713


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class three_d     {        int x, y, z;        public:        three_d() { x = y = z = 0; }        three_d(int i, int j, int k) { x = i; y = j; z = k; }        three_d operator()(three_d obj);        three_d operator()(int a, int b, int c);        friend ostream &operator<<(ostream &strm, three_d op);    };    three_d three_d::operator()(three_d obj)    {        three_d temp;        temp.x = (x + obj.x) / 2;        temp.y = (y + obj.y) / 2;        temp.z = (z + obj.z) / 2;        return temp;    }    three_d three_d::operator()(int a, int b, int c)    {        three_d temp;        temp.x = x + a;        temp.y = y + b;        temp.z = z + c;        return temp;    }        ostream &operator<<(ostream &strm, three_d op) {        strm << op.x << ", " << op.y << ", " << op.z << endl;        return strm;    }    int main()    {        three_d objA(1, 2, 3), objB(10, 10, 10), objC;        objC = objA(objB(100, 200, 300));        cout << objC;        return 0;    }

Choices:
- 55, 106, 156
- 55, 106
- 55, 106, 159
- 55, 106, 158


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int operate (int a, int b)    {        return (a * b);    }    float operate (float a, float b)    {        return (a / b);    }    int main ()    {        int x = 5, y = 2;        float n = 5.0, m = 2.0;        cout << operate (x, y);        cout << operate (n, m);        return 0;    }

Choices:
- 119
- 102.5
- 123.4
- 128.4


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()    {        int a, b;        int* c;        c = &a;        a = 200;        b = 200;        *c = 100;        b = *c;        cout << *c << " " << b;        return 0;    }

Choices:
- 100 200
- 100 0
- 200 200
- 100 100


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()    {        int x;        int *p;        x = 5;        p = &x;        cout << *p;        return 0;    }

Choices:
- 5
- 10
- memory address
- 15


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()     {        int x = 9;        int* p = &x;        cout << sizeof(p);        return 0;    }

Choices:
- 4
- 2
- Depends on compiler
- 8


Question:
What will be the output of the following C++ code?
    #include <stdio.h>     #include<iostream>    using namespace std;    int main()    {        int a = 21;        int c ;        c = a++;        cout << c;          return 0;    }

Choices:
- 21
- 22
- 23
- 20


Question:
What will be the output of the following C++ code?
    #include <stdio.h>     #include<iostream>    using namespace std;    int main()    {        int x = 5, y = 5;        cout << ++x << --y << endl;        return 0;    }

Choices:
- 55
- 64
- 46
- 45


Question:
What will be the output of the following C++ code?
    #include <stdio.h>     #include<iostream>    using namespace std;    int main()    {        int x = 5, y = 5, z;        x = ++x; y = --y;        z = x++ + y--;        cout << z;        return 0;    }

Choices:
- 10
- 11
- 9
- 12


Question:
What will be the output of the following C++ code?
    #include <stdio.h>     #include<iostream>     using namespace std;    int main()    {        int x = 5, y = 5, z;        x = ++x; y = --y;        z = x + ++x;        cout << z;        return 0;    }

Choices:
- 11
- 12
- 13
- 14


Question:
What will be the output of the following C++ code?
    #include <stdio.h>     #include<iostream>    using namespace std;    int main()    {        int num1 = 5;        int num2 = 3;        int num3 = 2;        num1 = num2++;        num2 = --num3;        cout << num1 << num2 << num3;        return 0;    }

Choices:
- 532
- 235
- 312
- 311


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <cstring>    using namespace std;    int main ()    {        char str1[10] = "Hello";        char str2[10] = "World";        char str3[10];        int  len ;        strcpy( str3, str1);        strcat( str1, str2);        len = strlen(str1);        cout << len << endl;        return 0;    }

Choices:
- 5
- 55
- 11
- 10


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <string>    using namespace std;    int main ()    {        string str ("microsoft");        string::reverse_iterator r;        for (r = str.rbegin() ; r < str.rend(); r++ )            cout << *r;        return 0;    }

Choices:
- microsoft
- micro
- tfosorcim
- tfos


Question:
What will be the output of the following C++ code?
   #include <iostream>   #include <string>   using namespace std;   int main ()   {       string str ("nobody does like this");       string key ("nobody");       size_t f;       f = str.rfind(key);       if (f != string::npos)           str.replace (f, key.length(), "everybody");       cout << str << endl;       return 0;   }

Choices:
- nobody does like this
- nobody
- everybody
- everybody does like this


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <string>    using namespace std;    int main ()    {        string str ("steve jobs is legend");        string::iterator it;        str.erase (str.begin()+ 5, str.end()-7);        cout << str << endl;              return 0;    }

Choices:
- jobs is
- steve legend
- steve
- steve jobs is


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <string>    using namespace std;    int main ()    {        string str ("Microsoft");        for (size_t i = 0; i < str.length();)        {            cout << str.at(i-1);        }        return 0;    }

Choices:
- M
- Microsoft
- Micro
- runtime error


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
	string str;
	cin>>str;
	cout<<str;
	return 0;
}

Choices:
- str
- Input provided by the user
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
	char str[] = "Hello World";
	cout<<str[0];
	return 0;
}

Choices:
- H
- e
- Error
- o


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
	char str[10];
	cin>>str;
	cout<<str;
	return 0;
}

Choices:
- Compiler-time Error
- Run-time Error
- Input given by the user
- Depends on the length of the string entered by the user


Question:
What will be the output of the following C++ code if the string entered by the user is “Hello World”?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
	string str;
	cin>>str;
	cout<<str;
	return 0;
}

Choices:
- Hello World
- Hello
- World
- Error


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
	char s1[6] = "Hello";
	char s2[6] = "World";
	char s3[12] = s1 + " " + s2;
	cout<<s3;
	return 0;
}

Choices:
- Hello World
- Hello
- World
- Error


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
	string s1 = "Hello";
	string s2 = "World";
	string s3 = s1 + " " + s2;
	cout<<s3;
	return 0;
}

Choices:
- Hello World
- Hello
- World
- Error


Question:
Which of the following is correct way of concatenating two string objects in C++?
way 1:
string s1 = "hello";
string s2 = "world";
string s3 = s1 + s2;

way 2:
string s1 = "hello";
string s2 = "world";
string s3 = s1.append(s2);

way 3:
string s1 = "hello";
string s2 = "world";
string s3 = strcat(s1,s2);

Choices:
- 1 and 2
- 2 and 3
- 1 and 3
- 1, 2 and 3


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(int argc, char const *argv[])
{
	const char *a = "Hello\0World";
	cout<<a;
	return 0;
}

Choices:
- Hello World
- Hello
- World
- Error


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(int argc, char const *argv[])
{
	string s("a");
	cout<<s;
	return 0;
}

Choices:
- a
- empty string
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
	string s('a');
	cout<<s;
	return 0;
}

Choices:
- a
- empty string
- Error
- Segmentation fault


Question:
Which is the correct way of concatenating a character at the end of a string object?
way 1:
string s;
s = s + 'a';

way 2:
string s;
s.push_back('a');

Choices:
- 1 only
- 2 only
- both of them
- both are wrong


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
  std::string str ("Sanfoundry.");
  str.back() = '!';
  std::cout << str << endl;
  return 0;
}

Choices:
- Sanfoundry.!
- Sanfoundry.
- Sanfoundry!
- Sanfoundry!.


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
  string str ("sanfoundry.");
  str.front() = 'S';
  cout << str << endl;
  return 0;
}

Choices:
- Sanfoundry
- Sanfoundry.
- sanfoundry
- sanfoundry.


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
  string str ("sanfoundry.");
  cout << str.substr(3).substr(4) << endl;
  return 0;
}

Choices:
- foundry.
- dry.
- oundry.
- found


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
  string str = "Sanfoundry!";
  cout<<str.capacity();
  cout<<str.size();
  return 0;
}

Choices:
- 1511
- 1111
- 1115
- 010


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A{
	int a;
public:
	A(int i){
		a = i;
	}
	void assign(int i){
		a = i;
	}
	int return_value(){
		return a;
	}
};
int main(int argc, char const *argv[])
{
	A obj;
	obj.assign(5);
	cout<<obj.return_value();
}

Choices:
- 5
- 55
- Error
- Segmentation Fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A{
	int a;
	A(){
		a = 5;
	}

public:
	void assign(int i){
		a = i;
	}
	int return_value(){
		return a;
	}
};
int main(int argc, char const *argv[])
{
	A obj;
	obj.assign(10);
	cout<<obj.return_value();
}

Choices:
- 5
- 10
- Error
- Segmentation fault


Question:
In the following C++ code how many times the string “A’s constructor called” will be printed?
#include <iostream>
#include <string>
using namespace std;
class A{
	int a;
public:
	A(){
		cout<<"A's constructor called";
	}
};
class B{
	static A a;
public:
	B(){
		cout<<"B's constructor called";
	}
	static A get(){
		return a;
	}
};
A B::a;
int main(int argc, char const *argv[])
{
	B b;
	A a1 = b.get();
	A a2 = b.get();
	A a3 = b.get();
}

Choices:
- 3
- 4
- 2
- 1


Question:
Which of the following represents the correct explicit call to a constructor of class A?
class A{
		int a;
	        public:
		A(int i)
                {
			a = i;
		}
       }

Choices:
- A a(5);
- A a;
- A a = A(5);
- A a = A();


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A{
	A(){
		cout<<"Constructor called";
	}
};
int main(int argc, char const *argv[])
{
	A a;
	return 0;
}

Choices:
- Constructor called
- Nothing printed
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A{

public:
	A(){
		cout<<"Constructor called";
	}
};
int main(int argc, char const *argv[])
{
	A *a;
	return 0;
}

Choices:
- Constructor called
- Nothing printed
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A{
public:
	int a;
};
int main(int argc, char const *argv[])
{
	A a1 = {10};
	A a2 = a1;
	cout<<a1.a<<a2.a;
	return 0;
}

Choices:
- 1010
- 87368746
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A{
public:
	int a;
	A(int a){
		this->a = a;
	}
};
int main(int argc, char const *argv[])
{
	A a1, a2(10);
	cout<<a2.a;
	return 0;
}

Choices:
- 10
- Compile time error
- Run-time error
- No output


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A{
public:
	int a;
	A(int a=0){
		this->a = a;
	}
};
int main(int argc, char const *argv[])
{
	A a1, a2(10);
	cout<<a2.a;
	return 0;
}

Choices:
- 010
- 100
- 001
- Error


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A{
public:
	int a;
	A(){
		cout<<"Constructor called";
	}
};
int main(int argc, char const *argv[])
{
	A *a1 = (A*)malloc(sizeof(A));
	return 0;
}

Choices:
- Constructor called
- Nothing printed
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A{
public:
	int a;
	A(){
		cout<<"Constructor called";
	}
} a;
int main(int argc, char const *argv[])
{
	return 0;
}

Choices:
- Constructor called
- Nothing printed
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class A    {        public:        A(int n )        {            cout << n;        }    };    class B: public A    {        public:        B(int n, double d)        : A(n)        {            cout << d;        }        };    class C: public B    {        public:        C(int n, double d, char ch)        : B(n, d)        {            cout <<ch;        }    };    int main()    {        C c(5, 4.3, 'R');        return 0;    }

Choices:
- 54.3R
- R4.35
- 4.3R5
- R2.6


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class BaseClass     {        protected:        int i;        public:        BaseClass(int x)         {            i = x;        }        ~BaseClass()         {        }    };    class DerivedClass: public BaseClass     {        int j;        public:        DerivedClass(int x, int y): BaseClass(y)        {            j = x;        }        ~DerivedClass()         {        }        void show()         {            cout << i << " " << j << endl;        }    };    int main()    {        DerivedClass ob(3, 4);        ob.show();        return 0;    }

Choices:
- 3 4
- 4 3
- 4
- 3


Question:
What will be the output of the following C++ code?
    #include<iostream>    using namespace std;    class X     {        int m;        public:        X() : m(10)        {                                                               }        X(int mm): m(mm)        {        }        int getm()        {            return m;        }    };    class Y : public X     {        int n;        public:        Y(int nn) : n(nn) {}                                                        int getn() { return n; }    };    int main()    {        Y yobj( 100 );        cout << yobj.getm() << " " << yobj.getn() << endl;    }

Choices:
- 10 100
- 100 10
- 10 10
- 100 100


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class p     {        protected:        int width, height;        public:        void set_values (int a, int b)        {            width = a; height = b;         }        virtual int area (void) = 0;    };    class r: public p    {        public:        int area (void)        {             return (width * height);        }    };    class t: public p     {        public:        int area (void)        {            return (width * height / 2);         }    };    int main ()     {        r rect;        t trgl;        p * ppoly1 = ▭        p * ppoly2 = &trgl;        ppoly1->set_values (4, 5);        ppoly2->set_values (4, 5);        cout << ppoly1 -> area() ;        cout << ppoly2 -> area();        return 0;    }

Choices:
- 1020
- 20
- 10
- 2010


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class MyInterface     {        public:        virtual void Display() = 0;    };    class Class1 : public MyInterface     {        public:        void Display()         {            int  a = 5;            cout << a;        }    };    class Class2 : public MyInterface     {        public:        void Display()        {            cout <<" 5" << endl;        }    };    int main()    {        Class1 obj1;        obj1.Display();        Class2 obj2;        obj2.Display();        return 0;    }

Choices:
- 5
- 10
- 5 5
- 15


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class sample    {        public:        virtual void example() = 0;     };    class Ex1:public sample    {        public:        void example()        {            cout << "ubuntu";        }    };    class Ex2:public sample    {        public:        void example()        {            cout << " is awesome";        }    };    int main()    {        sample* arra[2];        Ex1 e1;        Ex2 e2;        arra[0]=&e1;        arra[1]=&e2;        arra[0]->example();        arra[1]->example();    }

Choices:
- ubuntu
- is awesome
- ubuntu is awesome
- ubunt esome


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Base    {        public:        virtual void print() const = 0;    };    class DerivedOne : virtual public Base    {        public:        void print() const        {            cout << "1";        }    };    class DerivedTwo : virtual public Base    {        public:        void print() const        {            cout << "2";        }    };    class Multiple : public DerivedOne, DerivedTwo    {        public:        void print() const        {            DerivedTwo::print();        }    };    int main()    {        Multiple both;        DerivedOne one;        DerivedTwo two;        Base *array[ 3 ];        array[ 0 ] = &both;        array[ 1 ] = &one;        array[ 2 ] = &two;        for ( int i = 0; i < 3; i++ )        array[ i ] -> print();        return 0;    }

Choices:
- 121
- 212
- 12
- 215


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	int a;
    public:
	virtual void func() = 0;
};

class B: public A
{
   public:
	void func(){
		cout<<"Class B"<<endl;
	}
};

int main(int argc, char const *argv[])
{
	B b;
	b.func();
	return 0;
}

Choices:
- Class B
- Error
- Segmentation fault
- No output


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	int a;
   public:
	virtual void func() = 0;
};

class B: public A
{
   public:
	void func(){
		cout<<"Class B"<<endl;
	}
};

int main(int argc, char const *argv[])
{
	A a;
	a.func();
	return 0;
}

Choices:
- Class B
- Error
- Segmentation fault
- No output


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	int a;
    public:
	virtual void func() = 0;
};

class B: public A
{
    public:
	void func(){
		cout<<"Class B"<<endl;
	}
};

int main(int argc, char const *argv[])
{
	A *a;
	a->func();
	return 0;
}

Choices:
- Class B
- Error
- Segmentation fault
- No output


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class BaseClass     {        int i;        public:        void setInt(int n);        int getInt();    };    class DerivedClass : public BaseClass    {        int j;        public:        void setJ(int n);        int mul();    };    void BaseClass::setInt(int n)    {        i = n;    }    int BaseClass::getInt()    {        return i;    }    void DerivedClass::setJ(int n)    {        j = n;    }    int DerivedClass::mul()    {        return j * getInt();    }    int main()    {        DerivedClass ob;        ob.setInt(10);               ob.setJ(4);                  cout << ob.mul();            return 0;    }

Choices:
- 10
- 4
- 40
- 30


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class BaseClass     {        int x;        public:        void setx(int n)         {            x = n;        }        void showx()         {            cout << x ;        }    };    class DerivedClass : private BaseClass    {        int y;        public:        void setxy(int n, int m)        {            setx(n);                  y = m;        }        void showxy()         {            showx();                   cout << y << '\n';        }    };    int main()    {        DerivedClass ob;        ob.setxy(10, 20);        ob.showxy();        return 0;    }

Choices:
- 10
- 20
- 1020
- 1120


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class BaseClass     {        public:        virtual void myFunction()        {            cout << "1";        }    };    class DerivedClass1 : public BaseClass     {        public:        void myFunction()        {            cout << "2";        }    };   class DerivedClass2 : public DerivedClass1     {        public:        void myFunction()        {            cout << "3";        }    };    int main()    {        BaseClass *p;        BaseClass ob;        DerivedClass1 derivedObject1;        DerivedClass2 derivedObject2;        p = &ob;        p -> myFunction();        p = &derivedObject1;        p -> myFunction();        p = &derivedObject2;        p -> myFunction();        return 0;    }

Choices:
- 123
- 12
- 213
- 321


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class stu    {        protected:        int rno;        public:        void get_no(int a)        {            rno = a;        }        void put_no(void)        {        }    };    class test:public stu    {        protected:        float part1,part2;        public:        void get_mark(float x, float y)        {            part1 = x;            part2 = y;        }        void put_marks()        {        }    };    class sports    {        protected:        float score;        public:        void getscore(float s)        {            score = s;        }        void putscore(void)        {        }    };    class result: public test, public sports    {        float total;        public:        void display(void);    };    void result::display(void)    {        total = part1 + part2 + score;        put_no();        put_marks();        putscore();        cout << "Total Score=" << total << "\n";    }    int main()    {        result stu;        stu.get_no(123);        stu.get_mark(27.5, 33.0);        stu.getscore(6.0);        stu.display();        return 0;    }

Choices:
- 66.5
- 64.5
- 62.5
- 60.5


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class poly    {        protected:        int width, height;        public:        void set_values(int a, int b)        {            width = a; height = b;        }    };    class Coutput    {        public:        void output(int i);    };    void Coutput::output(int i)    {        cout << i;    }    class rect:public poly, public Coutput    {        public:        int area()        {            return(width * height);        }    };    class tri:public poly, public Coutput    {        public:        int area()        {            return(width * height / 2);        }    };    int main()    {        rect rect;        tri trgl;        rect.set_values(3, 4);        trgl.set_values(4, 5);        rect.output(rect.area());        trgl.output(trgl.area());        return 0;    }

Choices:
- 1212
- 1210
- 1010
- 1250


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    template <class T>    inline T square(T x)    {        T result;        result = x * x;        return result;    };    template <>    string square<string>(string ss)    {        return (ss+ss);    };    int main()         {        int i = 4, ii;        string ww("A");        ii = square<int>(i);        cout << i << ii;        cout << square<string>(ww) << endl;    }

Choices:
- 416AA
- 164AA
- AA416
- AA41A


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    template<typename type>    type Max(type Var1, type Var2)    {        return Var1 > Var2 ? Var1:Var2;    }    int main()    {        int p;        p = Max(100, 200);        cout << p << endl;        return 0;    }

Choices:
- 100
- 200
- 300
- 100200


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    template<typename type>    class TestVirt    {        public:        virtual type TestFunct(type Var1)        {            return Var1 * 2;        }    };    int main()    {        TestVirt<int> Var1;        cout << Var1.TestFunct(100) << endl;        return 0;    }

Choices:
- 100
- 200
- 50
- 150


Question:
What does this template function indicates?
==================
template<class T>
void func(T a)
{
	cout<<a;
}
==================

Choices:
- A function taking a single generic parameter and returning a generic type
- A function taking a single generic parameter and returning nothing
- A function taking single int parameter and returning a generic type
- A function taking a single generic parameter and returning a specific non-void type


Question:
What does this template function indicates?
==================
template<class T>
T func(T a)
{
	cout<<a;
}
==================

Choices:
- A function taking a single generic parameter and returning a generic type
- A function taking a single generic parameter and returning nothing
- A function taking single int parameter and returning a generic type
- A function taking a single generic parameter and returning a specific non-void type


Question:
What does this template function indicates?
==================
template<class T, class U>
U func(T a, U b)
{
	cout<<a<<"\t"<<b;
}
==================

Choices:
- A function taking a single generic parameter and returning a generic type which may be different from argument type
- A function taking a single generic parameter and returning a generic type which must be different from argument type
- A function taking a single generic parameter and returning a generic type which must have the same type as argument type
- A function taking a single generic parameter and returning a specific non-void type


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
template<class T>
T func(T a)
{
	cout<<a;
	return a;
}

template<class U>
void func(U a)
{
	cout<<a;
}

int main(int argc, char const *argv[])
{
	int a = 5;
	int b = func(a);
	return 0;
}

Choices:
- 5
- 55
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
template<class T>
T func(T a)
{
	cout<<a;
	return a;
}

int func(int a)
{
	cout<<a;
}

int main(int argc, char const *argv[])
{
	int a = 5;
	int b = func(a);
	float c = func(5.5);
	return 0;
}

Choices:
- 5
- 55.5
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
template<class T>
T func(T a)
{
	return a;
}

template<class T, class U>
T func(U a)
{
	return (T)a;
}

int main(int argc, char const *argv[])
{
	int a = 5;
	int b = func(a);
	int c = func(5.5);
	cout<<b<<c<<endl;
	return 0;
}

Choices:
- 5
- 55
- Error
- Segmentation fault


Question:
What type can be used to replace templates from this function?
template<class T, class U>
T func(T a, T b, U c)
{
	if(c == '+' || c){
		return a+b;
	}
	else if(c == '-' || !c){
		return a-b;
	}
}

Choices:
- replace templates T, U with auto keyword
- replace templates T, U with generic keyword
- replace templates T, U with temp keyword
- replace templates T, U with GEN_TEMP keyword


Question:
What is the syntax of an explicit call for a template? Assume the given template function.
template<class T, class U>
void func(T a, U b)
{
	cout<<a<<"\t"<<b<<endl;
}

Choices:
- func<int,char>(3,’a’);
- func(3,’a’)<int,char>;
- <int,char>func(3,’a’);
- func(<int>3,<char>’a’);


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    template <class type>    class Test    {        public:        Test()        {        };        ~Test()        {          };        type Funct1(type Var1)        {            return Var1;        }        type Funct2(type Var2)        {            return Var2;        }    };    int main()    {        Test<int> Var1;        Test<double> Var2;        cout << Var1.Funct1(200);        cout << Var2.Funct2(3.123);        return 0;    }

Choices:
- 100
- 200
- 3.123
- 2003.123


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    template <class T>    inline T square(T x)    {        T result;        result = x * x;        return result;    };    template <>    string square<string>(string ss)    {        return (ss+ss);    };    int main()    {        int i = 2, ii;        string ww("A");        ii = square<int>(i);        cout << i << ": " << ii;        cout << square<string>(ww) << ":" << endl;    }

Choices:
- 2: 4AA:
- 2:4
- AA
- 2:4A


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    template <typename T = float, int count = 3>    T multIt(T x)    {        for(int ii = 0; ii < count; ii++)        {            x = x * x;        }        return x;    };    int main()    {        float xx = 2.1;        cout << xx << ": " << multIt<>(xx) << endl;    }

Choices:
- 2.1
- 378.228
- 2.1: 378.228
- 376


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <string>    #include <cstring>    using namespace std;    template <class type>    type MyMax(const type Var1, const type Var2)    {        cout << "no specialization";        return Var1 < Var2 ? Var2 : Var1;    }    template <>    const char *MyMax(const char *Var1, const char *Var2)    {        return (strcmp(Var1, Var2)<0) ? Var2 : Var1;    }    int main()    {        string Str1 = "class", Str2 = "template";        const char *Var3 = "class";        const char *Var4 = "template";        const char *q = MyMax(Var3, Var4);        cout << q << endl;        return 0;    }

Choices:
- template
- class
- no specialization
- templateclass


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    template<class T = float, int i = 5> class A    {        public:        A();        int value;    };    template<> class A<>     {         public: A();     };    template<> class A<double, 10>    {         public: A();     };    template<class T, int i> A<T, i>::A() : value(i)    {        cout << value;    }    A<>::A()     {        cout << "default";    }    A<double, 10>::A()     {        cout << "10" << endl;    }    int main()     {        A<int, 6> x;        A<> y;        A<double, 10> z;    }

Choices:
- 6
- 10
- 6default10
- 6default


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class class0     {        public:        virtual ~class0(){}        protected:        char p;        public:        char getChar();    };    class class1 : public class0     {        public:        void printChar();    };    void class1::printChar()    {        cout  << "True" << endl;    }    int main()     {        class1 c;        c.printChar();        return 1;    }

Choices:
- True
- error
- no output
- runtime error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    template <class T>    class A    {        public:        A(int a): x(a) {}        protected:        int x;    };    template <class T>    class B: public A<char>    {        public:        B(): A<char>::A(100)         {            cout << x * 2 << endl;        }    };    int main()    {        B<char> test;        return 0;    }

Choices:
- 100
- 200
- error
- runtime error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    template <class type>    class Test    {        public:        Test();        ~Test();        type Data(type);    };    template <class type>    type Test<type>::Data(type Var0)    {        return Var0;    }    template <class type>    Test<type>::Test()    {    }    template <class type>    Test<type>::~Test()    {    }    int main(void)    {        Test<char> Var3;        cout << Var3.Data('K') << endl;        return 0;    }

Choices:
- k
- l
- error
- runtime error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Base    {        public:        Base ( )        {            cout << "1" << endl;        }        ~Base ( )        {            cout << "2" << endl;        }    };    class Derived : public Base    {        public:        Derived  ( )        {            cout << "3" << endl;        }        ~Derived ( )        {            cout << "4" << endl;        }        };     int main( )    {        Derived x;    }

Choices:
- 1234
- 4321
- 1423
- 1342


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
template <class T>
T max (T &a, T &b)
{
	cout << "Template Called ";
    return (a > b)? a : b;
}

template <>
int max <int> (int &a, int &b)
{
    cout << "Called ";
    return (a > b)? a : b;
}

int main ()
{
    int a = 10, b = 20;
    cout << max <int> (a, b);
}

Choices:
- Template Called 20
- Called 20
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
template<int n>
struct funStruct
{
    static const int val = 2*funStruct<n-1>::val;
};

template<>
struct funStruct<0>
{
    static const int val = 1 ;
};

int main()
{
    cout << funStruct<10>::val << endl;
    return 0;
}

Choices:
- 1
- 1024
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    double division(int a, int b)    {        if (b == 0)        {            throw "Division by zero condition!";        }        return (a / b);    }    int main ()    {        int x = 50;        int y = 0;        double z = 0;        try         {            z = division(x, y);            cout << z << endl;        }        catch (const char* msg)         {            cerr << msg << endl;        }        return 0;    }

Choices:
- 50
- 0
- Division by zero condition!
- Error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main ()     {        try        {            throw 20;        }        catch (int e)        {            cout << "An exception occurred " << e << endl;        }        return 0;    }

Choices:
- 20
- An exception occurred
- Error
- An exception occurred 20


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    using namespace std;    class myexception: public exception    {        virtual const char* what() const throw()        {            return "My exception";        }    } myex;    int main ()     {        try        {            throw myex;        }        catch (exception& e)        {            cout << e.what() << endl;        }        return 0;    }

Choices:
- Exception
- Error
- My exception
- Runtime error


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    using namespace std;    int main ()     {        try        {            int* myarray = new int[1000];            cout << "allocated";        }        catch (exception& e)        {            cout << "Standard exception: " << e.what() << endl;        }        return 0;    }

Choices:
- Allocated
- Standard exception
- Depends on the memory
- Error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()    {        double a = 10, b = 5, res;        char Operator = '/';        try         {            if (b == 0)                throw "Division by zero not allowed";            res = a / b;            cout << a << " / " << b << " = " << res;        }        catch(const char* Str)        {            cout << "\n Bad Operator: " << Str;        }        return 0;    }

Choices:
- 10
- 2
- Bad Operator
- 10 / 5 = 2


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()    {        try        {            throw 1;        }        catch (int a)        {            cout << "exception number:  " << a << endl;            return 0;        }        cout << "No exception " << endl;        return 0;    }

Choices:
- No exception
- exception number
- exception number: 1
- exception number: 5


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()    {        int a = 10, b = 20, c = 30;        float  d;        try        {            if ((a - b) != 0)            {                d = c / (a - b);                cout << d;            }            else            {                throw(a - b);            }        }        catch (int i)        {            cout<<"Answer is infinite "<<i;        }    }

Choices:
- 10
- -3
- 15
- 17


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    void test(int x)    {        try        {            if (x > 0)                throw x;            else                throw 'x';        }        catch(int x)        {            cout<<"integer:"<<x;        }        catch(char x)        {            cout << "character:" << x;        }    }    int main()    {        test(10);        test(0);    }

Choices:
- integer:10character:x
- integer:10
- character:x
- character:10


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    using namespace std;    class myexception: public exception    {        virtual const char* what() const throw()        {            return "exception arised";        }    } myex;    int main ()     {        try        {            throw myex;        }        catch (exception& e)        {            cout << e.what() << endl;        }        return 0;    }

Choices:
- exception arised
- error
- exception
- runtime error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()    {        int age=5;        try         {            if (age < 0)                throw "Positive Number Required";            cout  << age << "\n\n";        }        catch(const char* Message)        {            cout << "Error: " << Message;        }        return 0;    }

Choices:
- 5
- 10
- 15
- Positive Number Required


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    double division(int a, int b)    {        if ( b == 0 )        {            throw "Division by zero condition!";        }        return (a / b);    }    int main ()    {        int x = 50;        int y = 0;        double z = 0;        try         {            z = division(x, y);            cout << z << endl;        }        catch (const char* msg)         {            cout << msg << endl;        }        return 0;    }

Choices:
- 50
- 0
- Division by zero condition!
- 100


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <string>    using namespace std;    int main()    {        double Op1 = 10, Op2 = 5, Res;        char Op;        try         {               if (Op != '+' && Op != '-' && Op != '*' && Op != '/')                throw Op;            switch(Op)            {            case '+':                Res = Op1 + Op2;                break;            case '-':                Res = Op1 - Op2;                break;            case '*':                Res = Op1 * Op2;                break;            case '/':                Res = Op1 / Op2;                break;             }             cout << "\n" << Op1 << " " << Op << " "<< Op2 << " = " << Res;         }         catch (const char n)         {             cout << n << " is not a valid operator";         }         return 0;    }

Choices:
- 15
- 5
- 2
- is not a valid operator


Question:
What will be the output of the following C++ code?
    #include<iostream>    #include "math.h"    using namespace std;    double MySqrt(double d)    {        if (d < 0.0)        throw "Cannot take sqrt of negative number";             return sqrt(d);    }    int main()    {        double d = 5;        cout << MySqrt(d) << endl;    }

Choices:
- 5
- 2.236
- Error
- Cannot take sqrt of negative number


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <new>    using namespace std;    int main ()    {        int i, n;        int * p;        i = 2;        p= new (nothrow) int[i];        if (p == 0)            cout << "Error: memory could not be allocated";        else	{            for (n=0; n<i; n++)            {                p[n] = 5;            }            for (n = 0; n < i; n++)                cout << p[n];            delete[] p;         }         return 0;    }

Choices:
- 5
- 55
- 555
- Error: memory could not be allocated


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main(void)    {        const char *one = "Test";        cout << one << endl;        const char *two = one;        cout << two << endl;        return 0;    }

Choices:
- Test
- TestTest
- Te
- TestTe


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int funcstatic(int)    {        int sum = 0;        sum = sum + 10;        return sum;    }    int main(void)    {        int r = 5, s;        s = funcstatic(r);        cout << s << endl;        return 0;    }

Choices:
- 10
- 15
- error
- 20


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include<string.h>    using namespace std;    int main()    {        try        {            char *p;            strcpy(p, "How r u");        }        catch(const exception& er)        {        }    }

Choices:
- How r u
- segmentation fault
- error
- runtime error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()    {        int x = -1;        try         {            if (x < 0)            {                throw x;            }            else            {                cout<<x;            }        }        catch (int x )        {            cout << "Exception occurred: Thrown value is " << x << endl;        }        return 0;    }

Choices:
- -1
- 0
- Exception occurred: Thrown value is -1
- Error


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <typeinfo>    using namespace std;    class Polymorphic {virtual void Member(){}};    int main ()     {        try        {            Polymorphic * pb = 0;            typeid(*pb);           }        catch (exception& e)        {            cerr << "exception caught: " << e.what() << endl;        }        return 0;    }

Choices:
- exception caught: std::bad_typeid
- exception caught: std::bad_alloc
- exception caught: std::bad_cast
- exception caught: std::bad_id


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    using namespace std;    void myunexpected ()     {        cout << "unexpected handler called\n";        throw;    }    void myfunction () throw (int,bad_exception)     {        throw 'x';    }    int main (void)    {        set_unexpected (myunexpected);        try         {            myfunction();        }            catch (int)         {             cout << "caught int\n";         }        catch (bad_exception be)         {             cout << "caught bad_exception\n";         }        catch (...)         {             cout << "caught other exception \n";         }        return 0;    }

Choices:
- unexpected handler called
- caught bad_exception
- caught other exception
- both unexpected handler called & caught bad_exception


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;     int main()    {        int x = -1;        char *ptr;        ptr = new char[256];        try         {            if (x < 0)            {                throw x;            }            if (ptr == NULL)            {                throw " ptr is NULL ";            }        }        catch (...)         {            cout << "Exception occurred: exiting "<< endl;        }        return 0;    }

Choices:
- -1
- ptr is NULL
- exception occured: exiting
- 1


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    using namespace std;    void myunexpected ()    {        cout << "unexpected called\n";        throw 0;    }    void myfunction () throw (int)     {        throw 'x';    }    int main ()     {        set_unexpected (myunexpected);        try         {            myfunction();        }        catch (int)         {            cout << "caught int\n";        }        catch (...)          {             cout << "caught other exception\n";         }        return 0;    }

Choices:
- caught other exception
- caught int
- unexpected called
- both caught int & unexpected called


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    void empty() throw()     {        cout << "In empty()";    }    void with_type() throw(int)     {        cout << "Will throw an int";        throw(1);    }    int main()     {        try         {            empty();            with_type();        }        catch (int)         {            cout << "Caught an int";        }    }

Choices:
- In empty()
- Will throw an int
- Caught an int
- All of the mentioned


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    #include <typeinfo>    using namespace std;    class Test1    {            virtual int  Funct()         {        }    };    int main ()    {        try         {            Test1 * var = NULL;            typeid (*var);        }        catch (std::exception& typevar)        {            cout << "Exception: " << typevar.what() << endl;           }        return 0;    }

Choices:
- NULL
- Exception:bad_alloc
- Exception:std:bad_typeid
- Exception:std:bad_type


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <string>    #include<typeinfo>    using namespace std;    int main( )    {        try        {            string strg1("Test");            string strg2("ing");            strg1.append(strg2, 4, 2);            cout << strg1 << endl;        }        catch (exception &e)        {            cout << "Caught: " << e.what() << endl;            cout << "Type: " << typeid(e).name() << endl;        };        return 0;    }

Choices:
- out of range
- bad type_id
- bad allocation
- bad typ


Question:
What will be the output of the following C++ code?
    #include <typeinfo>    #include <iostream>    using namespace std;    class Myshape    {        public:        virtual void myvirtualfunc() const {}    };    class mytriangle: public Myshape    {        public:        virtual void myvirtualfunc() const        {           };    };    int main()    {        Myshape Myshape_instance;        Myshape &ref_Myshape = Myshape_instance;        try         {            mytriangle &ref_mytriangle = dynamic_cast<mytriangle&>(ref_Myshape);        }        catch (bad_cast)        {            cout << "Can't do the dynamic_cast lor!!!" << endl;            cout << "Caught: bad_cast exception. Myshape is not mytriangle.\n";        }        return 0;    }

Choices:
- Can’t do the dynamic_cast lor!!!
- Caught: bad_cast exception. Myshape is not mytriangle.
- Can’t able to create the dynamic instance for the triangle, So it is arising an exception
- Myshape is not mytriangle


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()    {        char* ptr;        unsigned long int Test = sizeof(size_t(0) / 3);        cout << Test << endl;        try        {            ptr = new char[size_t(0) / 3];            delete[ ] ptr;        }        catch (bad_alloc &thebadallocation)        {            cout << thebadallocation.what() << endl;        };        return 0;    }

Choices:
- 4
- 2
- bad_alloc
- depends on compiler


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Base    {        protected:        int a;        public:        Base()         {             a = 34;         }        Base(int i)        {             a = i;         }        virtual ~Base()         {             if (a < 0)  throw a;         }        virtual int getA()        {            if (a < 0)             {                 throw a;            }        }    };    int main()    {        try        {            Base b(-25);            cout << endl << b.getA();        }        catch (int)         {            cout << endl << "Illegal initialization";        }    }

Choices:
- Illegal initialization
- Terminate called after throwing an instance of ‘int’
- Illegal initialization & terminate called after throwing an instance
- initialization


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    #include <cstdlib>    using namespace std;    void myterminate ()     {        cerr << "terminate handler called";        abort();    }    int main (void)     {        set_terminate (myterminate);        throw 0;         return 0;    }

Choices:
- terminate handler called
- aborted
- both terminate handler & Aborted
- runtime error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Test1     {     };    class Test2 : public Test1 { };    void Funct();    int main()    {        try        {            Funct();        }        catch (const Test1&)        {            cerr << "Caught a exception" << endl;        }        return 0;    }    void Funct()    {        throw Test2();    }

Choices:
- Caught an exception
- NULL
- Both Caught an exception & NULL
- Caught a exception


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    #include <cstdlib>    #include <exception>    void Funct()    {        cout << "Funct() was called by terminate()." << endl;        exit(0);    }    int main()    {        try        {            set_terminate(Funct);            throw "Out of memory!";        }        catch(int)        {             cout << "Integer exception raised." << endl;         }        return 0;    }

Choices:
- Integer exception raised
- Funct() was called by terminate()
- Integer exception not raised
- Integer exception raised.


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    using namespace std;    int main ()     {        try        {            double* i= new double[1000];            cout << "Memory allocated";        }        catch (exception& e)        {            cout << "Exception arised: " << e.what() << endl;        }        return 0;    }

Choices:
- Memory allocated
- Exception arised
- Depends on the computer memory
- Memory allocatedException arised


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    void test(int x)    {        try        {            if (x > 0)                throw x;            else                throw 'x';        }        catch(char)        {            cout << "Catch a integer and that integer is:" << x;        }    }    int main()    {        cout << "Testing multiple catches\n:";        test(10);        test(0);    }

Choices:
- Catch a integer and that integer is:10
- Error
- Runtime error
- Catch a integer and that integer is:25


Question:
What will be the output of the following C++ code?
    #include <stdexcept>    #include <limits>    #include <iostream>    using namespace std;    void func(int c)    {        if (c < numeric_limits<char> :: max())            throw invalid_argument("MyFunc argument too large.");        else        {            cout<<"Executed";        }    }    int main()    {        try        {            func(256);        }        catch(invalid_argument& e)        {            cerr << e.what() << endl;            return -1;        }        return 0;    }

Choices:
- Invalid arguments
- Executed
- Error
- Runtime error


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <string>    using namespace std;    int main ()    {        int num = 3;        string str_bad = "wrong number used";        try        {            if ( num == 1 )            {                       throw 5;            }            if ( num == 2 )            {                throw 1.1f;            }            if ( num != 1 || num != 2 )            {                    throw str_bad;            }        }        catch (int a)        {            cout << "Exception is: " << a << endl;        }        catch (float b)        {            cout << "Exception is: " << b << endl;        }        catch (...)        {            cout  << str_bad << endl;        }        return 0;    }

Choices:
- Exception is 5
- Exception is 1.1f
- Wrong number used
- Exception is 1.6g


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    double division(int a, int b)    {        if (b == 0)        {            throw "Division by zero condition!";        }        return (a / b);    }    int main ()    {        int x = 50;        int y = 0;        double z = 0;        try         {            z = division(x, y);            cout << z << endl;        }        catch (const msg)         {            cerr << msg << endl;        }        return 0;    }

Choices:
- 50
- 0
- Division by zero condition
- Error


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

void func(int a, int b)
{

	if(b == 0){
		throw "This value of b will make the product zero. "
                      "So please provide positive values.\n";
	}
	else{
		cout<<"Product of "<<a<<" and  "<<b<<" is: "<<a*b<<endl;
	}
}

int main()
{
	try{
		func(5,0);
	}
	catch(const char* e){
		cout<<e;
	}
}

Choices:
- 0
- 5
- This value of b will make the product zero. So please provide positive values.
- Product of 5 and  0 is: 0


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void func(int a, int b)
{
	if(b == 0){
		throw "This value of b will make the product zero. "
                       "So please provide positive values.\n";
	}
	else{
		cout<<"Product of "<<a<<" and  "<<b<<" is: "<<a*b<<endl;
	}
}

int main()
{
	try{
		func(5,0);
	}
	catch(char* e){
		cout<<e;
	}
}

Choices:
- 0
- Aborted (core dumped)
- This value of b will make the product zero. So please provide positive values.
- Product of 5 and  0 is: 0


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void func(int a, int b)
{
	if(b < 1){
		throw b;
	}
	else{
		cout<<"Product of "<<a<<" and  "<<b<<" is: "<<a*b<<endl;
	}
}

int main()
{
	try
        {
		try
                {
		    func(5,-1);
		}
		catch(int b)
                {
			if(b==0)
				throw "value of b is zero\n";
			else
				throw "value of b is less than zero\n";
		}
	}
	catch(const char* e)
        {
		cout<<e;
	}

}

Choices:
- value of b is zero
- value of b is less than zero
- Product of 5 and  -1 is: -5
- Aborted(core dumped)


Question:
What happens when this C++ program is compiled?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class A
{
	int a;
    public:
	A(){}
};

class B: public A
{
	int b;
    public:
	B(){}
};

void func()
{
	B b;
	throw b;
}

int main()
{
	try{
		func();
	}
	catch(A a){
		cout<<"Caught A Class\n";
	}
	catch(B b){
		cout<<"Caught B Class\n";
	}
}

Choices:
- The program compiles successfully without any errors or warnings
- Compile-time error occurs
- The program compiles successfully with warnings
- The program gives both errors and warnings


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class A
{
	int a;
    public:
	A(){}
};

class B: public A
{
	int b;
    public:
	B(){}
};

void func()
{
	B b;
	throw b;
}

int main()
{
	try{
		func();
	}
	catch(A a){
		cout<<"Caught A Class\n";
	}
	catch(B b){
		cout<<"Caught B Class\n";
	}
}

Choices:
- Caught B Class
- Caught A Class
- Compile-time error
- Run-time error


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class A
{
	int a;
   public:
	A(){}
};

class B: public A
{
	int b;
    public:
	B(){}
};

void func()
{
	B b;
	throw b;
}

int main()
{
	try{
		func();
	}
	catch(B b){
		cout<<"Caught B Class\n";
	}
	catch(A a){
		cout<<"Caught A Class\n";
	}
}

Choices:
- Caught B Class
- Caught A Class
- Compile-time error
- Run-time error


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class A
{
	int a;
    public:
	A(){}
};
class B: public A
{
	int b;
    public:
	B(){}
};

void func()
{
	B b;
	throw b;
}
int main()
{
	try{
		func();
	}
	catch(B *b){
		cout<<"Caught B Class\n";
	}
	catch(A a){
		cout<<"Caught A Class\n";
	}
}

Choices:
- Caught B Class
- Caught A Class
- Compile-time error
- Run-time error


Question:
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
    try
    {
        try
        {
            throw 20;
        }
        catch (int n)
        {
            cout << "Inner Catch\n";
            throw;
        }
    }
    catch (int x)
    {
        cout << "Outer Catch\n";
    }
    return 0;
}

Choices:
- i, iii
- i, ii, iii
- i, ii
- ii, iii


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    void Division(const double a, const double b);    int main()    {        double op1=0, op2=10;        try         {            Division(op1, op2);        }        catch (const char* Str)        {            cout << "\nBad Operator: " << Str;        }        return 0;    }    void Division(const double a, const double b)    {        double res;        if (b == 0)            throw "Division by zero not allowed";        res = a / b;        cout << res;    }

Choices:
- 0
- Bad operator
- 10
- 15


Question:
What will be the output of the following C++ code?
    #include <stdexcept>    #include <limits>    #include <iostream>    using namespace std;    void MyFunc(char c)    {        if (c < numeric_limits<char>::max())            return invalid_argument;    }    int main()    {        try        {            MyFunc(256);        }        catch(invalid_argument& e)        {            cerr << e.what() << endl;            return -1;        }        return 0;    }

Choices:
- 256
- Invalid argument
- Error
- 246


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    using namespace std;    class myexc: public exception    {        virtual const char* what() const throw()        {            return "My exception";        }    } myex;    int main ()     {        try        {            throw myex;        }        catch (exception& e)        {            cout << e.what() << endl;        }        return 0;    }

Choices:
- My
- My exception
- No exception
- exception


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    using namespace std;    int main ()     {        try        {            int* myarray= new int[1000];            cout << "Allocated";        }        catch (exception& e)        {            cout << "Standard exception: " << e.what() << endl;        }        return 0;    }

Choices:
- Allocated
- Standard exception:
- bad_alloc
- Depends on memory


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    int main()    {        char* ptr;        unsigned long int a = (size_t(0) / 3);        cout << a << endl;        try        {            ptr = new char[size_t(0) / 3];            delete[ ] ptr;        }        catch(bad_alloc &thebadallocation)        {            cout << thebadallocation.what() << endl;        };        return 0;    }

Choices:
- 0
- 2
- bad_alloc
- depends on compiler


Question:
What will be the output of the following C++ code?
    #include <typeinfo>    #include <iostream>    using namespace std;    class shape    {        public:        virtual void myvirtualfunc() const {}    };    class mytriangle: public shape    {        public:        virtual void myvirtualfunc() const        {           };    };    int main()    {        shape shape_instance;        shape &ref_shape = shape_instance;        try         {            mytriangle &ref_mytriangle = dynamic_cast<mytriangle&>(ref_shape);        }        catch (bad_cast)         {            cout << "Caught: bad_cast exception\n";        }        return 0;    }

Choices:
- Caught standard exception
- No exception arises
- Caught: bad_cast exception
- Caught: cast


Question:
What will be the output of the following C++ code?
    #include <typeinfo>    #include <iostream>    using namespace std;    class Test    {        public:        Test();        virtual ~Test();    };    int main()    {        Test *ptrvar = NULL;        try         {            cout << typeid(*ptrvar).name() << endl;        }        catch (bad_typeid)         {            cout << "The object is null" << endl;        }        return 0;    }

Choices:
- No exception arises
- The object is null
- Error
- The object is


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <sstream>    using namespace std;    int main()    {        stringstream mys(ios :: in | ios :: out);        std :: string dat("The double value is : 74.79 .");        mys.str(dat);        mys.seekg(-7, ios :: end);        double val;        mys >> val;        val = val*val;        mys.seekp(-7,ios::end);        mys << val;        std :: string new_val = mys.str();        cout << new_val;        return 0;    }

Choices:
- 5593.54
- Error
- Runtime error
- 5463.54


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Base    {        public:            Base(){}            ~Base(){}            protected:            private:     };    class Derived:public Base    {        public:            Derived(){}            Derived(){}            private:            protected:    };    int main()    {        cout << "The program exceuted" << endl;    }

Choices:
- The program executed
- Error
- Runtime error
- program exceuted


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class MyException    {        public:        MyException(int value) : mValue(value)        {        }        int mValue;    };    class MyDerivedException : public MyException    {        public:            MyDerivedException(int value, int anotherValue) : MyException(value),    mAnotherValue(anotherValue)            {            }            int mValue;            int mAnotherValue;    };    void doSomething()    {        throw MyDerivedException(10,20);    }    int main()    {        try        {            doSomething();        }        catch (MyDerivedException &exception)        {            cout << "\nCaught Derived Class Exception\n";        }        catch (MyException &exception)        {            cout << "\nCaught Base Class Exception\n";        }        return 0;    }

Choices:
- Caught Base Class Exception
- Caught Derived Class Exception
- Caught Base & Derived Class Exception
- Caught Base Class


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <string>    using namespace std;    int main()     {        string s = "a long string";        s.insert(s.size() / 2, " * ");        cout << s << endl;        return 0;    }

Choices:
- a long* string
- a long st*ring
- Depends on compiler
- a long string*


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Base    {        public:        virtual void print() const = 0;    };    class DerivedOne : public Base    {        public:             void print() const        {            cout << "DerivedOne\n";        }    };    class DerivedTwo : public Base    {        public:        void print() const        {            cout << "DerivedTwo\n";        }         };     class Multiple : public DerivedOne, public DerivedTwo    {        public:        void print() const        {            DerivedTwo :: print();        }     };     int main()    {        int i;        Multiple both;         DerivedOne one;         DerivedTwo two;         Base *array[ 3 ];         array[ 0 ] = &both;         array[ 1 ] = &one;        array[ 2 ] = &two;        array[ i ] -> print();        return 0;    }

Choices:
- DerivedOne
- DerivedTwo
- Error
- DerivedThree


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class student    {        public:        int rno , m1 , m2 ;        void get()        {            rno = 15, m1 = 10, m2 = 10;        }    };    class sports    {        public:        int sm;        void getsm()        {            sm = 10;        }    };    class statement:public student,public sports    {        int tot,avg;        public:        void display()        {            tot = (m1 + m2 + sm);            avg = tot / 3;            cout << tot;            cout << avg;        }    };    int main()    {        statement obj;        obj.get();        obj.getsm();        obj.display();    }

Choices:
- 3100
- 3010
- 2010
- 1010


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    struct a    {        int count;    };    struct b    {        int* value;    };    struct c : public a, public b    {    };    int main()    {        c* p = new c;        p->value = 0;        cout << "Inherited";        return 0;    }

Choices:
- Inherited
- Error
- Runtime error
- inherited


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Base1    {        protected:        int SampleDataOne;        public:        Base1()        {            SampleDataOne = 100;        }        ~Base1()        {        }        int SampleFunctOne()        {            return SampleDataOne;        }    };    class Base2    {        protected:        int SampleDataTwo;        public:        Base2()        {            SampleDataTwo = 200;        }        ~Base2()        {        }        int SampleFunctTwo()        {            return SampleDataTwo;        }    };    class Derived1 : public Base1, public Base2    {        int MyData;        public:        Derived1()         {            MyData = 300;        }        ~Derived1()        {        }            int MyFunct()        {            return (MyData + SampleDataOne + SampleDataTwo);        }    };    int main()    {        Base1 SampleObjOne;        Base2 SampleObjTwo;        Derived1 SampleObjThree;        cout << SampleObjThree.Base1 :: SampleFunctOne() << endl;        cout << SampleObjThree.Base2 :: SampleFunctTwo() << endl;        return 0;    }

Choices:
- 100
- 200
- Both 100 & 200
- 150


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	int a, b;
	float d;
   public:
	void change(int i){
		a = i;
	}
	void value_of_a(){
		cout<<a;
	}
};

class B: private A
{

};

int main(int argc, char const *argv[])
{
	B b;
	cout<<sizeof(B);
	return 0;
}

Choices:
- 8
- 12
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	float d;
    public:
	int a;
	void change(int i){
		a = i;
	}
	void value_of_a(){
		cout<<a;
	}
};

class B: public A
{
	int a = 15;
    public:
	void print(){
		cout<<a;
	}
};

int main(int argc, char const *argv[])
{
	B b;
	b.change(10);
	b.print();
	b.value_of_a();

	return 0;
}

Choices:
- 1010
- 1510
- 1515
- 5110


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A{
	float d;
   public:
	virtual void func(){
		cout<<"Hello this is class A\n";
	}
};

class B: public A{
	int a = 15;
public:
	void func(){
		cout<<"Hello this is class B\n";
	}
};

int main(int argc, char const *argv[])
{
	B b;
	b.func();
	return 0;
}

Choices:
- Hello this is class B
- Hello this is class A
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	float d;
     public:
	virtual void func(){
		cout<<"Hello this is class A\n";
	}
};

class B: public A
{
	int a = 15;
   public:
	void func(){
		cout<<"Hello this is class B\n";
	}
};

int main(int argc, char const *argv[])
{
	A *a;
	a->func();
	return 0;
}

Choices:
- Hello this is class A
- Hello this is class B
- Error
- Segmentation Fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	float d;
   public:
	virtual void func(){
		cout<<"Hello this is class A\n";
	}
};

class B: public A
{
	int a = 15;
   public:
	void func(){
		cout<<"Hello this is class B\n";
	}
};

int main(int argc, char const *argv[])
{
	A *a = new A();
	B b;
	a = &b;
	a->func();
	return 0;
}

Choices:
- Hello this is class A
- Hello this is class B
- Error
- Segmentation Fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class Mammal
{
   public:
	virtual void Define(){
		cout<<"I'm a Mammal\n";
	}
};

class Human: public Mammal
{
   public:
	void Define(){
		cout<<"I'm a Human\n";
	}
};

class Male: public Human
{
   public:
	void Define(){
		cout<<"I'm a Male\n";
	}
};

class Female: public Human
{
   public:
	void Define(){
		cout<<"I'm a Female\n";
	}
};

int main(int argc, char const *argv[])
{
	Mammal *M;
	Male m;
	Female f;
	*M = m;
	M->Define();
	return 0;
}

Choices:
- I’m a Male
- I’m a Mammal
- Error
- Segmentation Fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class Mammal
{
   public:
	virtual void Define(){
		cout<<"I'm a Mammal\n";
	}
};

class Human: public Mammal
{
   private:
	void Define(){
		cout<<"I'm a Human\n";
	}
};

int main(int argc, char const *argv[])
{
	Mammal *M = new Mammal();
	Human H;
	M = &H;
	M->Define();
	return 0;
}

Choices:
- Error
- Segmnetation fault
- I’m a Human
- Garbage Value


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
   public:
	virtual A(){
		cout<<"A's Constructor\n";
	}
};

class B: public A
{
   public:
	A(){
		cout<<"Present inside the class B\n";
	}
};

int main(int argc, char const *argv[])
{
	A a;
	return 0;
}

Choices:
- A’s Constructor
- Present inside the class B
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
   public:
	virtual static void show(){
		cout<<"class A\n";
	}
};

class B: public A
{
   public:
	static void show(){
		cout<<"class B\n";
	}
};

int main(int argc, char const *argv[])
{
	A *a = new A();
	B b;
	a = &b;
	a->show();
	return 0;
}

Choices:
- class B
- Error
- Segmentation fault
- class A


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	int a;
   public:
	A(){
		a = 0;
	}
	static void show(){
		a++;
		cout<<a;
	}
};

class B: public A
{
   public:

};

int main(int argc, char const *argv[])
{
	B b;
	b.show();
	return 0;
}

Choices:
- 1
- 0
- Segmentation fault
- Error


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	int a;
   public:
	A(){
		a = 0;
	}
	void show(){
		a++;
		cout<<"a: "<<a<<endl;
	}
};

class B: public A
{
   public:
};

int main(int argc, char const *argv[])
{
	B b;
	b.show();
	return 0;
}

Choices:
- a: 1
- a: 0
- Error
- Segmentation fault


Question:
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	int a;
   public:
	A(){
		a = 0;
	}
	void show(){
		a++;
		cout<<"a: "<<a<<endl;
	}
};

class B: private A
{
   public:

};

int main(int argc, char const *argv[])
{
	B b;
	b.show();
	return 0;
}

Choices:
- Error
- Segmentation fault
- a: 1
- a: 0


Question:
What happens if the following C++ program is compiled?
#include <iostream>
#include <string>
using namespace std;
class A
{
	int a;
   public:
	A(){
		a = 0;
	}
	void show(){
		a++;
		cout<<"a: "<<a<<endl;
	}
};

class B: private A
{
   public:
	void show(){
		show();
	}
};

int main(int argc, char const *argv[])
{
	B b;
	b.show();
	return 0;
}

Choices:
- Error because of the conflicts between two show() function in class B
- Program will compile successfully
- Error due to self call in show() function
- Error because show() function from class A is derived privately


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class student    {        public:        int rno , m1 , m2 ;        protected:        void get()        {            rno = 15, m1 = 10, m2 = 10;        }    };    class sports    {        public:        int sm;        void getsm()        {            sm = 10;        }    };    class statement : public student, public sports    {        int tot, avg;        public:        void display()        {            tot = (m1 + m2 + sm);            avg = tot / 3;            cout << tot;            cout << avg;        }        void setObject()        {            get();        }    };    int main()    {        statement obj;        obj.setObject();        obj.getsm();        obj.display();    }

Choices:
- 3010
- 1010
- 2100
- Error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;     struct A     {        int i;        char j;        float f;        void func();    };    void A :: func() {}    struct B     {        public:        int i;        char j;        float f;        void func();    };    void B :: func() {}    int main()     {        A a; B b;        a.i = b.i = 1;         a.j = b.j = 'c';        a.f = b.f = 3.14159;        a.func();        b.func();        cout << "Allocated";         return 0;    }

Choices:
- Allocated
- Error
- 3.14159
- 1


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    struct A     {        private:        int i, j, k;        public:        int f();        void g();    };    int A :: f()     {        return i + j + k;    }    void A :: g()     {        i = j = k = 0;    }    class B     {        int i, j, k;        public:        int f();        void g();    };    int B :: f()     {        return i + j + k;     }    void B :: g()     {        i = j = k = 0;    }    int main()     {        A a;        B b;        a.f();         a.g();        b.f();         b.g();        cout << "Identical results would be produced";    }

Choices:
- 50
- Identical results would be produced
- Error
- Runtime error


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Cat    {        public:        int age;        int weight;    };    int main()    {        Cat f;        f.age = 56;        cout << "Gates is " ;        cout << f.age << " years old.\n";    }

Choices:
- Gates is
- Gates is 56 years old
- Error
- Gates is 53 years old


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    struct X;    struct Y     {        void f(X*);    };    struct X     {        private:        int i;        public:        void initialize();         friend void g(X* , int);        friend void Y :: f(X*);        friend struct Z;        friend void h();    };    void X :: initialize()     {        i = 0;    }    void g(X* x, int i)     {        x -> i = i;    }    void Y :: f(X * x)     {        x -> i = 47;        cout << x->i;    }    struct Z     {        private:        int j;        public:        void initialize();        void g(X* x);    };    void Z::initialize()     {        j = 99;    }    void Z::g(X* x)     {        x -> i += j;    }    void h()     {        X x;        x.i = 100;        cout << x.i;    }    int main()     {        X x;        Z z;        z.g(&x);        cout << "Data accessed";    }

Choices:
- 99
- 47
- Data accessed
- 67


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <exception>    using namespace std;    class base { virtual void dummy() {} };    class derived: public base { int a; };    int main ()     {        try         {            base * pba = new derived;            base * pbb = new base;            derived * pd;            pd = dynamic_cast<derived*>(pba);            if (pd == 0)                 cout << "Null pointer on first type-cast" << endl;            pd = dynamic_cast<derived*>(pbb);            if (pd == 0)                 cout << "Null pointer on second type-cast" << endl;        }         catch (exception& e)         {            cout << "Exception: " << e.what();        }        return 0;    }

Choices:
- Null pointer on first type-cast
- Null pointer on second type-cast
- Exception
- Null pointer on third type-cast


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <typeinfo>    using namespace std;    int main ()     {        int * a;        int b;        a = 0; b = 0;        if (typeid(a) != typeid(b))        {            cout << typeid(a).name();            cout << typeid(b).name();        }        return 0;    }

Choices:
- Pi
- i
- Both pi & i
- f


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <typeinfo>    #include <exception>    using namespace std;    class base     {         virtual void f(){}     };    class derived : public base {};    int main ()     {        try         {            base* a = new base;            base* b = new derived;            cout << typeid(*a).name() << '\t';            cout << typeid(*b).name();        }         catch (exception& e)         {             cout << "Exception: " << e.what() << endl;         }        return 0;    }

Choices:
- base*
- derived*
- 4base and 7derived
- Exception:derived


Question:
What will be the output of the following C++ code?
    #include <typeinfo>    #include <iostream>    using namespace std;    class A    {        public:        virtual ~A();    };    int main()     {        A* a = NULL;        try         {            cout << typeid(*a).name() << endl;         }        catch (bad_typeid)        {            cout << "Object is NULL" << endl;        }    }

Choices:
- int
- float
- double
- object is NULL


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    struct A     {        virtual void f()          {             cout << "Class A" << endl;         }    };    struct B : A     {        virtual void f()         {             cout << "Class B" << endl;        }    };    struct C : A     {        virtual void f()         {            cout << "Class C" << endl;         }    };    void f(A* arg)     {        B* bp = dynamic_cast<B*>(arg);        C* cp = dynamic_cast<C*>(arg);        if (bp)            bp -> f();        else if (cp)            cp -> f();        else            arg -> f();      };    int main()     {        A aobj;        C cobj;        A* ap = &cobj;        A* ap2 = &aobj;        f(ap);        f(ap2);    }

Choices:
- Class C
- Class A
- Both Class C & A
- Class D


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Car    {        public:        int speed;    };    int main()    {        int Car :: *pSpeed = &Car :: speed;        Car c1;        c1.speed = 1;                   cout << c1.speed << endl;        c1.*pSpeed = 2;             cout  << c1.speed << endl;        return 0;    }

Choices:
- 1
- 2
- Both 1 & 2
- 4


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    class Foo    {        public:        Foo(int i = 0){ _i = i;}        void f()        {            cout << "Executed"<<endl;        }        private:        int _i;    };    int main()    {        Foo *p = 0;        p -> f();    }

Choices:
- Executed
- Error
- Runtime error
- 10


Question:
What will be the output of the following C++ code?
    #include <new>    #include <iostream>    using namespace std;    struct A     {        virtual ~A() {  };        void operator delete(void* p)         {            cout << "A :: operator delete" << endl;        }    };    struct B : A     {        void operator delete(void* p)         {            cout << "B :: operator delete" << endl;        }    };    int main()     {        A* ap = new B;        delete ap;    }

Choices:
- A::operator delete
- B::operator delete
- Both A::operator delete & B::operator delete
- A:operator new


Question:
What will be the output of the following C++ code?
    #include <iostream>    using namespace std;    struct A    {        virtual ~A()        {             cout << "~A()" << endl;         }        void operator delete[](void* p, size_t)        {            cout << "A :: operator delete[]" << endl;            delete [] p;        }    };    struct B : A     {        void operator delete[](void* p, size_t)         {            cout << "B :: operator delete[]" << endl;            delete [] p;        }    };    int main()     {        A* bp = new B[3];        delete[] bp;    };

Choices:
- ~A()
- A :: operator delete[]
- B :: operator delete[]
- Warning


Question:
What will be the output of the following C++ code?
    #include <cstdlib>    #include <iostream>    using namespace std;    class X     {        public:        void* operator new(size_t sz) throw (const char*)        {            void* p = malloc(sz);            if (p == 0)                 throw "malloc() failed";            return p;        }        void operator delete(void* p)         {            cout << "X :: operator delete(void*)" << endl;            free(p);        }     };    class Y     {        int filler[100];        public:        void operator delete(void* p, size_t sz) throw (const char*)        {            cout << "Freeing " << sz << " bytes" << endl;            free(p);        };    };    int main()     {        X* ptr = new X;        delete ptr;        Y* yptr = new Y;        delete yptr;    }

Choices:
- X::operator delete(void*)
- Freeing 400 bytes
- Depends on the compiler
- Both X::operator delete(void*) & Depends on the compiler


Question:
What will be the output of the following C++ code?
    #include <new>    #include<cstdlib>    #include <iostream>    using namespace std;    class X;    struct Node     {        X* data;        bool filled;        Node() : filled(false) { }    };    class X     {        static Node buffer[];        public:        int number;        enum { size = 3};        void* operator new(size_t sz) throw (const char*)        {            void* p = malloc(sz);            if (sz == 0)                throw "Error: malloc() failed";            cout << "X :: operator new(size_t)" << endl;            return p;        }        void *operator new(size_t sz, int location) throw (const char*)         {            cout << "X :: operator new(size_t, " << location << ")" << endl;            void* p = 0;            if (location < 0 || location >= size || buffer[location].filled == true)            {                throw "Error: buffer location occupied";            }            else             {                p = malloc(sizeof(X));                if (p == 0)                     throw "Error: Creating X object failed";                buffer[location].filled = true;                buffer[location].data = (X*) p;            }            return p;        }        static void printbuffer()         {            for (int i = 0; i < size; i++)             {                cout << buffer[i].data->number << endl;            }        }     };    Node X::buffer[size];    int main()    {        try         {            X* ptr1 = new X;            X* ptr2 = new(0) X;            X* ptr3 = new(1) X;            X* ptr4 = new(2) X;            ptr2->number = 10000;            ptr3->number = 10001;            ptr4->number = 10002;            X :: printbuffer();            X* ptr5 = new(0) X;        }        catch (const char* message)         {            cout << message << endl;        }    }

Choices:
- X::operator new(size_t)
- Error
- Runtime error
- operator new(size_d)


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <new>    #include <cstdlib>    using namespace std;    const int bsize = 512;    int *pa;    bool allocate = true;    void get_memory()     {        cerr << "free store exhausted" << endl;        delete [] pa;        allocate = false;    }    void eat_memory(int size)     {        int *p = new int[size];        if (allocate)            eat_memory(size);        else            cerr << "free store addr = " << p << endl;    }    int main()    {        set_new_handler(get_memory);        pa = new int[bsize];        cerr << "free store addr = " << pa << endl;        eat_memory(bsize);        return 0;    }

Choices:
- free store addr
- Error
- Segmentation fault
- free store exhausted


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <vector>    using namespace std;    int main()    {        vector<int> v;        v.assign( 10, 42 );        for (int i = 0; i < v.size(); i++)         {            cout << v[i] << " ";        }    }

Choices:
- 42
- 42 42
- 424
- 42 for 10 times


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <list>    #include <queue>    using namespace std;    int main()    {        queue<char> q;        q.push('a');        q.push('b');        q.push('c');        cout << q.front();        q.pop();        cout << q.front();        q.pop();        cout << q.front();        q.pop();    }

Choices:
- ab
- abc
- a
- error


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <vector>    #include <iterator>    #include <stddef.h>    using namespace std;    template<class myType>    class SimpleContainer    {        public:        SimpleContainer(size_t xDim, size_t yDim, myType const& defaultValue)        : objectData(xDim * yDim, defaultValue)        , xSize(xDim)        , ySize(yDim)        {        }        myType& operator()(size_t x, size_t y)        {            return objectData[y * xSize + x];        }        myType const& operator()(size_t x, size_t y) const         {            return objectData[y * xSize + x];        }        int getSize()        {            return objectData.size();        }        void inputEntireVector(vector<myType> inputVector)        {            objectData.swap(inputVector);        }        void printContainer(ostream& stream)        {            copy(objectData.begin(), objectData.end(),            ostream_iterator<myType>(stream, ""/*No Space*/));        }        private:        vector<myType> objectData;        size_t  xSize;        size_t  ySize;    };    template<class myType>    inline ostream& operator<<(ostream& stream, SimpleContainer<myType>& object)    {        object.printContainer(stream);        return stream;    }    void sampleContainerInterfacing();    int main()    {        sampleContainerInterfacing();        return 0;    }    void sampleContainerInterfacing()    {        static int const ConsoleWidth  = 80;        static int const ConsoleHeight = 25;        size_t width  = ConsoleWidth;        size_t height = ConsoleHeight;        SimpleContainer<int> mySimpleContainer(width, height, 0);        cout << mySimpleContainer.getSize() << endl;        mySimpleContainer(0, 0) = 5;    }

Choices:
- 2000
- No Space
- Error
- Depends on the compiler


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <vector>    using namespace std;    int main ()    {        unsigned int i;        vector<int> first;        vector<int> second (4, 100);        vector<int> third (second.begin(), second.end());        vector<int> fourth (third);        int myints[] = {16, 2, 77, 29};        vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );        for (vector<int> :: iterator it = fifth.begin(); it != fifth.end(); ++it)            cout << ' ' << *it;        return 0;    }

Choices:
- 16
- 16 2
- 16 2 77
- 16 2 77 29


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <vector>    using namespace std;    int main ()    {        vector<int> myvector;        int sum (0);        myvector.push_back (100);        myvector.push_back (200);        myvector.push_back (300);        while (!myvector.empty())        {            sum += myvector.back();            myvector.pop_back();        }        cout << sum << '\n';        return 0;    }

Choices:
- 500
- 600
- 700
- Error


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <vector>    using namespace std;    int main ()    {        vector<int> first;        first.assign (7,100);        vector<int>::iterator it;        it=first.begin()+1;        int myints[] = {1776,7,4};        cout << int (first.size()) << '\n';        return 0;    }

Choices:
- 10
- 9
- 8
- 7


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <vector>    using namespace std;    int main ()    {        vector<int> myvector (5);        int* p = myvector.data();        *p = 10;        ++p;        *p = 20;        p[2] = 100;        for (unsigned i = 0; i < myvector.size(); ++i)            cout << ' ' << myvector[i];        return 0;    }

Choices:
- 10 20 0 100 0
- 10 20 0 100
- 10 20 0
- 10 20


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <deque>    using namespace std;    int main ()    {        deque<int> mydeque (5);          deque<int>::reverse_iterator rit = mydeque.rbegin();        int i = 0;        for (rit = mydeque.rbegin(); rit!= mydeque.rend(); ++rit)            *rit = ++i;        for (deque<int> :: iterator it = mydeque.begin();        it != mydeque.end(); ++it)        cout << ' ' << *it;        return 0;    }

Choices:
- 12345
- 1234
- 54321
- 43210


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <deque>    using namespace std;    int main ()    {        unsigned int i;        deque<int> a (3,100);        deque<int> b (5,200);        a.swap(b);        cout << "a contains:";        for (deque<int>::iterator it = a.begin(); it != a.end(); ++it)            cout << ' ' << *it;        cout << "b contains:";        for (deque<int>::iterator it = b.begin(); it != b.end(); ++it)            cout << ' ' << *it;        return 0;    }

Choices:
- a contains: 200 200 200 200 200b contains: 100 100 100
- a contains: 100 100 100 100 100b contains: 200 200 200
- a contains: 200 200 200 200 200b contains: 200 200 200
- a contains: 200 200 200 200 200b contains: 100 200 150


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <deque>    using namespace std;    int main ()    {        unsigned int i;        deque<int> mydeque;        mydeque.push_back (100);        mydeque.push_back (200);        mydeque.push_back (300);        for(deque<int> :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)        {        }        mydeque.clear();        mydeque.push_back (110);        mydeque.push_back (220);        for(deque<int> :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)            cout << ' ' << *it;        cout << '\n';        return 0;    }

Choices:
- 110
- 220
- Both 110 & 220
- 330


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <vector>    using namespace std;    int main ()    {        vector<int> myvector;        int * p;        unsigned int i;        p = myvector.get_allocator().allocate(5);        for (i = 0; i < 5; i++)             myvector.get_allocator().construct(&p[i], i);        for (i = 0; i < 5; i++)            cout << ' ' << p[i];        for (i = 0; i < 5; i++)            myvector.get_allocator().destroy(&p[i]);        myvector.get_allocator().deallocate(p, 5);        return 0;    }

Choices:
- 1 2 3 4 5
- 0 1 2 3 4
- 1 2 3 4
- 5 4 3 2 1


Question:
What will be the output of the following C++ code?
    #include <iostream>    #include <cmath>    #include <list>    using namespace std;    bool same_integral_part (double first, double second)    {          return ( int(first) == int(second) );     }    struct is_near     {        bool operator() (double first, double second)        {             return (fabs(first - second) < 5.0);         }    };    int main ()    {        double mydoubles[] = { 12.15,  2.72, 73.0,  12.77,  3.14, 12.77, 73.35, 72.25, 15.3,  72.25 };        list<double> mylist (mydoubles, mydoubles + 10);        mylist.sort();        mylist.unique();        mylist.unique (same_integral_part);        mylist.unique (is_near());        for (list<double> :: iterator it = mylist.begin(); it != mylist.end(); ++it)            cout << ' ' << *it;        cout << '\n';        return 0;    }

Choices:
- 2.72 12.15 72.25
- 12.15 73.0 12.77
- 73.35
- 74.45