Question 21

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

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    #include <sstream>
    #include <string>
    using namespace std;
    int main(void)
    {
    string s;
    s = "Test";
    s.resize (s.size() ? 1);
    cout<<s<<" "<<s.size();
    return 0;
    }
  • Question 23

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    class complex{
    double re;
    double im;
    public:
    complex() : re(0),im(0) {}
    complex(double x) { re=x,im=x;};
    complex(double x,double y) { re=x,im=y;}
    void print() { cout << re << " " << im;}
    };
    int main(){
    complex c1;
    c1 = 3.0;
    c1.print();
    return 0;
    }
  • Question 24

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    #include <string>
    using namespace std;
    class First
    {
    string *s;
    public:
    First() { s = new string("Text");}
    ~First() { delete s;}
    void Print(){ cout<<*s;}
    };
    int main()
    {
    First FirstObject;
    FirstObject.Print();
    FirstObject.~First();
    }
  • Question 25

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    int main()
    {
    const int x=0;
    const int *ptr;
    ptr = &x;
    cout<<*ptr;
    return 0;
    }