Skip to content

Instantly share code, notes, and snippets.

@jrmmendes
Created December 2, 2018 18:10
Show Gist options
  • Save jrmmendes/81e21a3d0114ee1a2f24eacf8bc13434 to your computer and use it in GitHub Desktop.
Save jrmmendes/81e21a3d0114ee1a2f24eacf8bc13434 to your computer and use it in GitHub Desktop.
Exemplo sobre a ordem de uso de funções
// ----------------------------------------------------//
// 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