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.
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 4. Kapittel 8
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Suggested prompts:
Still meg spørsmål om dette emnet
Oppsummer dette kapittelet
Vis eksempler fra virkeligheten
Awesome!
Completion rate improved to 2.94
Pass by Reference
Sveip for å vise menyen
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.
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 4. Kapittel 8