Question from the C++ - Fundamentals test

Write a C++ function that takes an integer reference as an argument and increments it by 1.

Waiting for validation
Original question

What does the following code display ?

void f(int& x) {
    x = x + 1;
    cout << "x=" << x << endl;
}

int main() {
   int val(1);
   f(val);
   cout << "val=" << val << endl;
   return 0;
}
New question

What does the following code display ?

void f(int& x) {
    x = x + 1;
    cout << "x=" << x << endl;
}

int main() {
   int val(1);
   f(val);
   cout << "val=" << val << endl;
   return 0;
}
Author: Damien BegonStatus: Waiting for validation(Update)Question not yet passed
0
Community EvaluationsNo one has reviewed this question yet, be the first!