Question du test C++ - Les bases

Écrire une fonction C++ qui prend un entier en référence en argument et l'incrémente de 1.

Intermédiaire

Qu'affiche le code suivant ?

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

int main() {
   int val(1);
   f(val);
   cout << "val=" << val << endl;
   return 0;
}
Auteur: SamuelStatut : PubliéeQuestion passée 267 fois
Modifier
0
Évaluations de la communauté
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