Question 11

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main(){
int i = 1;
for(i=10; i>-1; i/=2) {
if(!i)
break;
}
cout << i;
return 0;
}
  • Question 12

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

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    int fun(int x) {
    return 2*x;
    }
    int main(){
    int i;
    i = fun(0.5) || fun(0);
    cout << i;
    return 0;
    }
  • Question 14

    Which code, inserted at line 8, generates the output "0102020"?
    #include <iostream>
    using namespace std;
    class Base {
    static int age;
    public:
    Base () {};
    ~Base () {};
    //insert code here
    void Print() { cout << age;}
    };
    int Base::age=0;
    int main () {
    Base a,*b;
    b = new Base();
    a.Print();
    a.setAge(10);
    a.Print();
    b?>setAge();
    a.Print();
    b?>Print();
    return 0;
    }
  • Question 15

    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;
    }