Pass by Reference
By reference:
12345678910void incValue(int &x) { x++; } int main() { int x = 1; incValue(x); cout << x; return 0; }
Here we change x as the function works with the address (reference) of this variable. It can be useful in case you need to change the value of the parameters.
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 4. Luku 8
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Suggested prompts:
Kysy minulta kysymyksiä tästä aiheesta
Tiivistä tämä luku
Näytä käytännön esimerkkejä
Awesome!
Completion rate improved to 2.94
Pass by Reference
Pyyhkäise näyttääksesi valikon
By reference:
12345678910void incValue(int &x) { x++; } int main() { int x = 1; incValue(x); cout << x; return 0; }
Here we change x as the function works with the address (reference) of this variable. It can be useful in case you need to change the value of the parameters.
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 4. Luku 8