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

bookPass by Value

When we pass function arguments, there are two ways to do this:

  • By value: the function's variable copies the parameter's value without changing the argument.
  • By reference: the function's variable copies the reference of the parameter by changing the argument.

By value:

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; }
copy

As you can see by the output, x didn't change since we changed the copy of x in the function incValue().

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 7

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

Awesome!

Completion rate improved to 2.94

bookPass by Value

Glissez pour afficher le menu

When we pass function arguments, there are two ways to do this:

  • By value: the function's variable copies the parameter's value without changing the argument.
  • By reference: the function's variable copies the reference of the parameter by changing the argument.

By value:

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; }
copy

As you can see by the output, x didn't change since we changed the copy of x in the function incValue().

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 7
some-alt