Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Pass by Reference | Functions
C++ Intermediate | Mobile-Friendly

Pass by Reference

Glissez pour afficher le menu

By reference:

12345678910
void incValue(int &x) { &nbsp;&nbsp;&nbsp;&nbsp;x++; } int main() { &nbsp;&nbsp;&nbsp;&nbsp;int x = 1; &nbsp;&nbsp;&nbsp;&nbsp;incValue(x); &nbsp;&nbsp;&nbsp;&nbsp;cout << x; &nbsp;&nbsp;&nbsp;&nbsp;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.

question mark

What the main difference between passing by value and by reference?

Sélectionnez toutes les réponses correctes

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 8

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Section 4. Chapitre 8
some-alt