Ask Question
6 September, 20:53

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';

+2
Answers (1)
  1. 6 September, 21:04
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers