About DEV C ++ data inconsistencies
I wrote a function of the sum of the array, and hackerrank where you can run the entire line, which is the site for exercises in the second question. In DEV C ++ code I wrote as follows:
#include <stdio.h>
using namespace std;
int simpleArraySum(int ar[]) {
int x=ar[3];
int a=sizeof(ar);
int b=sizeof(ar[1]);
int count=sizeof(ar)/sizeof(ar[0]);
int sum=0;
for(int i=0;i<count;i++){
sum+=ar[i];
}
return sum;
}
int main(){
int ar[]={1,2,3,4};
int c=sizeof(ar);
int result=simpleArraySum(ar);
cout<<"result="<<result;
return 0;
}
We can see the value of a variable c and should have equal sizeof (ar), but when I found during debugging a problem, inconsistent both. The results below debugging:
A =. 8, C = 16, and according to the results of x = ar [3] = 4, see the array pass in the right, it is clear there is a problem in the data transmission process ah, the last count the result is not the 1 + 2 + 3 + 4 = 10, while only 1 + 2 = 3.
However, this code runs hackerrank in on the right
there is the big brother who can come out to answer wow?