Ask Question
11 June, 08:52

What will the following code display? #include using namespace std; void doSomething (int); int main () { int x{2}; cout << x << '/n'; doSomething (x); cout << x << '/n'; return 0; } void doSomething (int num) { num = 0; cout << num << '/n';

+4
Answers (1)
  1. 11 June, 08:54
    0
    The code will display the following on the screen:-

    2

    0

    2

    Explanation:

    The output is like this because x{2} assigns the value 2 to the integer x. First the value of x is printed on the screen that is 2 and that newline is used to go to the next line. After that function is called doSomething with x passed as the argument. doSomething function assigns the value zero to the variable passed and prints it on the screen. So the next line is 0. Since x is passed by value so no changes will appear in the original argument. Hence the last line printed is 2.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What will the following code display? #include using namespace std; void doSomething (int); int main () { int x{2}; cout ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers