Question from the C++ - Fundamentals test

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

Medium

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: SamuelStatus: PublishedQuestion passed 296 times
Edit
0
Community Evaluations
developer avatar
Auteur anonyme
29/08/2024
Hi you put a std::endl then a, b, c and d are wrong and the correct answer would be : x=2 val=2
developer avatar
Auteur anonyme
02/09/2024
Indeed