Created
May 14, 2017 17:44
-
-
Save fbarrios/2ffcaff1b0889587b20bff7472641f72 to your computer and use it in GitHub Desktop.
Dos formas de devolver un valor en C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Forma #1: por valor de retorno | |
int obtener_valor() | |
{ | |
return 4; | |
} | |
int main() | |
{ | |
int x = obtener_valor(); | |
// Uso el valor de x. | |
return 0; | |
} | |
// Forma #2: por referencia de parámetro | |
void obtener_valor(int* x) | |
{ | |
*x = 4; | |
} | |
int main() | |
{ | |
int x; | |
obtener_valor(&x); | |
// Uso el valor de x. | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment