C Arrays gives address instead of value when second array is created -


first of all, sorry english. hope still understand problem is.

i new c programming , bit confused. here code.

#include <stdio.h> #include "tableaux.h"  int main(int argc, const char * argv[]) {   int tableauun[4] = {1, 1, 1, 1};   printf("%d\n", sommetableau(tableauun, 4));  printf("%d\n", moyennetableau(tableauun, 4));   return 0;  } 

and file functions are. have file have prototypes.

#include <stdio.h> #include "tableaux.h"   int sommetableau(int tableau[], int taille) {     int resultat;      (int = 0; < taille; i++) {         resultat += tableau[i];     }     return resultat; }  int moyennetableau(int tableau[], int taille) {     int resultat;      (int = 0; < taille; i++) {         resultat += tableau[i];     }      return resultat / taille; }  void copiertableau(int tableau[], int taille, int tableaudeux[]) {     (int = 0; < taille; i++) {         tableaudeux[i] = tableau[i];     } } 

so works fine. first printf gives me total of values stored in array , second 1 gives me average of values.

5 1 program ended exit code: 0 

what don't understand why result when want create second array ?

int tableauun[4] = {1, 1, 1, 1}; int tableaudeux[4] = {0}; 

the result

1606416356 1 program ended exit code: 0 

so haven't used second array result of first printf changes , bit confused going on.

i hope can me !

please initialize sum return in function

int resultat = 0; 

otherwise resultat take garbage value initial value


Comments