I have an exercise in C ++ / C to make the average of an array using the "pointer formalism" ("formalisme pointeur" in French). For example, this next one uses the "pointer formalism" to manipulate the table:
int tab[10];
for{int i = 0 ; i < 10 ; i ++ )
{
*(tab + i) = 0
}
But this one uses the "table formalism":
int tab[10];
for{int i = 0 ; i < 10 ; i ++ )
{
tab[i] = 0
}
I do not understand well if they do the same thing ...
However I have done the following to calculate the average of a table of 10 numbers with the "table formalism" how to do it with the "pointer formalism"?
#include<iostream>
#include <fstream>
using namespace std;
//Écrire, de deux manières différentes, un programme qui lit 10 nombres entiers et les stocke dans un tableau statique de taille 10 avant de calculer la media des éléments de ce tableau
void mediaTableau(int tabula[]){
int media = 0;
for(int i = 0; i<sizeof(tabula); i++){
media = tableauEntiers[i] +moyenne;
}
cout << "media tabula " << media/sizeof(tabula) <<endl;
}
int main(){
static int tabula[10];
cout << "Da diez numeros" <<endl;
for(int i = 0; i<10; i++){
cin >> tabula[i];
cout << "numero " << i+1 <<endl;
}
mediaTableau(tabula);
return 0;
}