Question 76

What is the output of the program?
#include <iostream>
using namespace std;
#define PRINT(i) cout<<i;
int main()
{
int y=2, z=3;
PRINT(y);
PRINT(z);
return 0;
}
  • Question 77

    Given:
    #include <iostream>
    #include <exception>
    using namespace std;
    int main () {
    try
    {
    int * myarray= new int[1000];
    }
    catch (bad_alloc&)
    { cout << "Error allocating memory"; } catch (exception& e) { cout << "Standard exception"; } catch (...) { cout << "Unknown exception"; } return 0; }
    What will happen if we use the operator "new" and the memory cannot be allocated?
  • Question 78

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    int main(){
    int i = 1;
    if (i++==1) {
    cout << i;
    } else {
    cout << i-1;
    }
    return 0;
    }
  • Question 79

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

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    class A {
    public:
    void Print(){ cout<<"A";}
    };
    class B:public A {
    public:
    virtual void Print(){ cout<< "B";}
    };
    class C:public B {
    public:
    void Print(){ cout<< "C";}
    };
    int main()
    {
    A ob1;
    B ob2;
    C ob3;
    B *obj;
    obj = &ob2;
    obj?>Print();
    obj = &ob3;
    obj?>Print();
    }