Question 36

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 37

    Which of the following structures are correct?
    1:
    struct s1{ int x; char c;
    };
    2:
    struct s2{ float f; struct s2 *s;
    };
    3:
    struct s3{ float f; in i;
    }
  • Question 38

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    int main()
    {
    int *t;
    t = new int[2];
    for (int i=0; i<2; i++) {
    t[i] = i;
    }
    cout << t[1];
    }
  • Question 39

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

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    #include <string>
    using namespace std;
    class B;
    class A {
    int age;
    public:
    A () { age=5; };
    friend class B;
    };
    class B {
    string name;
    public:
    B () { name="Bob"; };
    void Print(A ob) {
    cout << name << ob.age;
    }
    };
    int main () {
    A a;
    B b;
    b.Print(a);
    return 0;
    }