Question 71

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 );
}
  • Question 72

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    #include <string>
    using namespace std;
    class A {
    public:
    A() { cout << "A no parameters";}
    A(string s) { cout << "A string parameter";}
    A(A &a) { cout << "A object A parameter";}
    };
    class B : public A {
    public:
    B() { cout << "B no parameters";}
    B(string s) { cout << "B string parameter";}
    B(int s) { cout << "B int parameter";}
    };
    int main () {
    A a2("Test");
    B b1(10);
    B b2(b1);
    return 0;
    }
  • Question 73

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    class Test {
    float i,j;
    };
    class Add {
    public:
    int x,y;
    Add (int a=3, int b=3) { x=a; y=b; }
    int result() { return x+y;}
    };
    int main () {
    Test test;
    Add * padd;
    padd = &test;
    cout << padd?>result();
    return 0;
    }
  • Question 74

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    struct {
    int x;
    char c;
    union {
    float f;
    int i;
    };
    } s;
    int main (int argc, const char * argv[])
    {
    s.x=10;
    s.i=0;
    cout << s.i << " " << s.x;
    }
  • Question 75

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