Question 56

What is the output of the program if character "1" is supplied as input?
#include <iostream>
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw 'a';
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}
  • Question 57

    What will variable "y" be in class B?
    class A { int x; protected: int y; public: int age;
    };
    class B : public A {
    string name;
    public:
    void Print() {
    cout << name << age;
    }
    };
  • Question 58

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    class BaseC
    {
    int *ptr;
    public:
    BaseC() { ptr = new int(10);}
    BaseC(int i) { ptr = new int(i); }
    ~BaseC() { delete ptr; }
    void Print() { cout << *ptr; }
    };
    int main()
    {
    BaseC *o = new BaseC(5);
    o?>Print();
    }
  • Question 59

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    int main(int argc, char *argv[]) {
    char *s = "ABCDEF";
    cout << s+2;
    return 0;
    }
  • Question 60

    What is the output of the program?
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
    string s1="Wo";
    string s2;
    s2 = s1;
    string s3;
    s3 = s2.append("rldHello");
    cout << s3;
    return( 0 );
    }