mercredi 20 octobre 2021

I don't understand a part of the C++ code, can someone explain it?

I was wondering if someone could explain why the f2(a,a); is 13 13 and not 12 12?

Does this have something to do with the & sign, if so what does it mean?

Thanks in advance!

#include <iostream>

using namespace std;

void f1 (int a, int b){
 a = 12; b = 13;
}
void f2 (int& a, int& b){
a = 12; b = 13;
}


int main()
{
 int a = 10; int b = 11;
 f1(a,b);
 cout << a << ' ' << b << ' ';
 f2(a,b);
 cout << a << ' ' << b << ' ';
 f2(a,a);
 cout << a << ' ' << b;

}

Aucun commentaire:

Enregistrer un commentaire