Ask Question
18 November, 01:07

What is the output of the following program?#include using namespace std; void doSomething (∫); int main () {int x = 2; cout << x << endl; doSomething (x); cout << x << endl; return 0; }void doSomething (int &num) {num = 0; cout << num << endl; }

+1
Answers (1)
  1. 18 November, 03:32
    0
    The outputs of the code is

    2

    0

    2

    Explanation:

    First, I'll arrange the code line by line. While arranging the code, I'll make some corrections

    #include

    using namespace std;

    void doSomething ();

    int main () {

    int x = 2;

    cout << x <
    doSomething (x);

    cout << x << endl;

    return 0;

    }

    void doSomething (int &num)

    {

    num = 0;

    cout << num << endl;

    }

    At line 6, the value of x which is 2 is printed and the line is terminated to prevent printing of value on the same line. So, the next print statement will start on the next line.

    At line 7, the function doSomething () is called.

    This statement will execute the instructions in the doSomething () function and print value 0. This line is also terminated.

    At line 8, the value of x is printed which is also 2
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is the output of the following program?#include using namespace std; void doSomething (∫); int main () {int x = 2; cout ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers