Pass 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:
12345678910void incValue(int x) { x++; } int main() { int x = 1; incValue(x); cout << x; return 0; }
As you can see by the output, x
didn't change since we changed the copy of x
in the function incValue()
.
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 4. Capítulo 7
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Suggested prompts:
Pregunte me preguntas sobre este tema
Resumir este capítulo
Mostrar ejemplos del mundo real
Awesome!
Completion rate improved to 2.94
Pass by Value
Desliza para mostrar el menú
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:
12345678910void incValue(int x) { x++; } int main() { int x = 1; incValue(x); cout << x; return 0; }
As you can see by the output, x
didn't change since we changed the copy of x
in the function incValue()
.
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 4. Capítulo 7