En el primer bucle que recorre con ++
de la función me retorna 29 y la segunda que recorre con +i
me retorna 30 , pero ambas deberían retornar 29. ¿Que estoy haciendo?
#include <iostream>
using namespace std;
int sumaElementos(int a[],int tam){
int acum=0;
int *p;
p = &a[0];
//BUCLE 1
for(int i=0;i<tam;i++){
acum+=*p++;
} //RETORNA 29
//BUCLE 2
/*for(int i=0;i<tam;i++){
acum+=*p+i;
}*/ //RETORNA 30
return acum;
}
int main(){
int arreglo[5]={4,9,6,7,3};
cout<<sumaElementos(arreglo,5);
return 0;
}