Question 116

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
namespace myNamespace1
{
int x = 5;
int y = 10;
}
namespace myNamespace2
{
float x = 3.14;
float y = 1.5;
}
int main () {
{
using namespace myNamespace1;
cout << x << " ";
}{
using namespace myNamespace2;
cout << y;
}
return 0;
}
  • Question 117

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    class A {
    public:
    int x;
    A() { x=0;}
    };
    class B : public A {
    public:
    B() { x=1;}
    };
    class C : private B {
    public:
    C() { x=2;}
    };
    int main () {
    C c1;
    cout << c1.x;
    return 0;
    }
  • Question 118

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    class A { public: virtual void Print()=0; }; class B:public A {
    public:
    virtual void Print(){ cout<< "B";}
    };
    int main()
    {
    B ob2;
    A *obj;
    obj = &ob2;
    obj->Print();
    }
  • Question 119

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    #include <string>
    using namespace std;
    class A {
    int x;
    protected:
    int y;
    public:
    int z;
    };
    class B : private A {
    string name;
    public:
    void set() {
    x = 1;
    }
    void Print() {
    cout << x;
    }
    };
    int main () {
    B b;
    b.set();
    b.Print();
    return 0;
    }
  • Question 120

    What will happen when you attempt to compile and run the following code?
    #include <iostream>
    #include <string>
    using namespace std;
    int fun(int);
    int main()
    {
    int *x = new int;
    *x=10;
    cout << fun(*x);
    return 0;
    }
    int fun(int i)
    {
    return i*i;
    }