hi. I have written a code to calculate the total of the members of an array named "arr". It doesnt work
Im sure it is easy so please tell we where im doing wrong:
Code:
#include <cstdlib>
#include<iostream>
using namespace std;
int summ(int *p){
int res=0;
while(*p!=NULL){
res+=*p;
p++;
cout << "res="<<res<<" p="<<*p<<endl;
}
return res;
}
int main(int argc, char** argv) {
int arr[4]={5,1,2,6};
// int size=sizeof(arr)/sizeof(int);
// for(int i=0;i<size;i++){
// arr[i] = arr[i]*2;
// }
//
// cout << "size = " << size<<endl;
int v=summ(arr);
cout << v;
}
When i uncommend the part above, it works but i wanna learn how to pass a pointer in functions. So thx a lot in advance.