Question 51

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int compare(int, int);
int main()
{
int x = compare(10, 20);
cout << x;
return 0;
}
int compare(int i, int j)
{
return i<j;
}
  • Question 52

    Which code, inserted at line 15, generates the output "5 Bob"?
    #include <iostream>
    #include <string>
    using namespace std;
    class B;
    class A {
    int age;
    public:
    A () { age=5; };
    friend void Print(A &ob, B &so);
    };
    class B {
    string name;
    public:
    B () { name="Bob"; };
    //insert code here
    };
    void Print(A &ob, B &so) {
    cout<<ob.age << " " << so.name;
    }
    int main () {
    A a;
    B b;
    Print(a,b);
    return 0;
    }
  • Question 53

    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 : public A {
    string name;
    public:
    void set() {
    y = 2;
    z = 3;
    }
    void Print() { cout << y << z; }
    };
    int main () {
    B b;
    b.set();
    b.Print();
    return 0;
    }
  • Question 54

    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 55

    Which code, inserted at line 12, generates the output "5b"?
    #include <iostream> using namespace std; namespace myNamespace1 { int var = 5; } namespace myNamespace2 { char var = 'b'; } int main () { //insert code here return 0; }