Consider the following two C++ programs P1 and P2 and two statements S1 and S2…

Consider the following two C++ programs P1 and P2 and two statements S1 and S2 about these programs:

Program P1

void f(int a, int *b, int &c)
{
    a = 1;
    *b = 2;
    c = 3;
}

int main()
{
    int i = 0;
    f(i, &i, i);
    cout << i;
}

Program P2

double a = 1, b = 2;

double &f(double &d)
{
    d = 4;
    return b;
}

int main()
{
    f(a) = 5;
    cout << a << ":" << b;
}

Statements

  • S1: P1 prints out 3

  • S2: P2 prints out 4:2

  1. A.

    Neither S1 nor S2 is true

  2. B.

    Only S2 is true

  3. C.

    Both S1 and S2 are true

  4. D.

    Only S1 is true

Attempted by 24 students.

Sign up free to check your answer

Sign up free

Explore the full course: Isro

Loading lesson…