Created
December 2, 2018 18:10
-
-
Save jrmmendes/81e21a3d0114ee1a2f24eacf8bc13434 to your computer and use it in GitHub Desktop.
Exemplo sobre a ordem de uso de funções
This file contains hidden or 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
// ----------------------------------------------------// | |
// Assim funciona // | |
// ----------------------------------------------------// | |
int soma(int a, int b){ | |
return a + b; | |
} | |
int somatorio(int numeros[], int quantidade_de_numeros){ | |
// testes dos parâmetros, etc | |
int buffer = 0; | |
for(int i = 0; i < quantidade_de_numeros; ++i){ | |
buffer = soma(buffer, numeros[i]); // usando a função apenas pelo exemplo | |
} | |
return buffer; | |
} | |
int main(){ | |
// Código da main | |
} | |
// ----------------------------------------------------// | |
// Assim não funciona // | |
// ----------------------------------------------------// | |
int somatorio(int numeros[], int quantidade_de_numeros){ | |
// testes dos parâmetros, etc | |
int buffer = 0; | |
for(int i = 0; i < quantidade_de_numeros; ++i){ | |
buffer = soma(buffer, numeros[i]); // usando a função apenas pelo exemplo | |
} | |
return buffer; | |
} | |
int soma(int a, int b){ | |
return a + b; | |
} | |
int main(){ | |
// Código da main | |
} | |
// ----------------------------------------------------// | |
// Assim funciona também // | |
// ----------------------------------------------------// | |
int soma(int a, int b); | |
int somatorio(int numeros[], int quantidade_de_numeros); | |
int main(){ | |
// Código da main | |
} | |
int somatorio(int numeros[], int quantidade_de_numeros){ | |
// testes dos parâmetros, etc | |
int buffer = 0; | |
for(int i = 0; i < quantidade_de_numeros; ++i){ | |
buffer = soma(buffer, numeros[i]); // usando a função apenas pelo exemplo | |
} | |
return buffer; | |
} | |
int soma(int a, int b){ | |
return a + b; | |
} | |
// No ultimo caso, a ordem não é importante |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment