Possible Duplicate:
How to find the sizeof(a pointer pointing to an array)
I have the following program that counts the biggest diff between positions in array, but the sizeof function does not print out what expected. when passing the 10 ints big array and i measure it with sizeof it prints out that it is 8 ints long, how come?
#include <stdlib.h>
#include <stdio.h>
int *
measure(int *arr)
{
int *answer=malloc(sizeof(int)*10);
answer[0]=0;
answer[1]=0;
int size=sizeof(arr)+1;
printf("%d\n", size);
int i;
for(i=0; i<size; i++)
{
signed int dif=arr[i]-arr[i+1];
if(dif<0)
dif*=-1;
if(dif>answer[1])
{
answer[1]=dif;
answer[0]=i;
}
}
return answer;
}
int
main (void)
{
int arr[10]={77, 3, 89, 198, 47, 62, 308, 709, 109, 932};
int *ans=measure(arr);
printf("the biggest dif is %d between nrs %d and %d\n", ans[1], ans[0], ans[0]+1);
return 0;
}