Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++, What is the output ? #include <iostream> using namespace std; void fun2(

ID: 3929489 • Letter: I

Question

In C++, What is the output ?

#include <iostream>

using namespace std;

void fun2(int& a, int& b, int c, int& d)

{

        int temp;

        temp = a;

        a = b;

        b = c;

        c = d;

        d = temp;

}

void main()

{

        int a, b, c, d;

        a = b = c = d = 0;

        for(int i = 0; i < 2; i++){

               fun2(a, b, c, d);

               a += 4;

               b -= 3;

               c *= 2;

               d -= 1;

        }

        cout << a << " " << b << " " << c << " " << d << endl;

}

Explanation / Answer

Answer :

#include <iostream>

using namespace std;

void fun2(int& a, int& b, int c, int& d)

{

     int temp;

     temp = a;

     a = b;

     b = c;

     c = d;

    d = temp;

}

void main()

{

        int a, b, c, d;

        a = b = c = d = 0;

        for(int i = 0; i < 2; i++){

               fun2(a, b, c, d);

               a += 4;

               b -= 3;

               c *= 2;

               d -= 1;

        }

        cout << a << " " << b << " " << c << " " << d << endl;

}

Answer :

1 -3 0 3