Hi everyone,

I am trying to calculate the number of elements of an array that I pass as an argument to a function but I am not getting what I thought I should get.
I am using sizeof(array)/sizeof(array[0]) both inside and outside the function and I am getting different answers for each one.

Code:


#include <stdio.h>
#include <math.h>


void calculateSize(float array[]);


int main(int argc, const char * argv[]) {

    float balance[] = {10, 100, 500, 400};



    int size = sizeof(balance)/sizeof(balance[0]);

    printf("Outside function        size: %d\n\n",size);


    calculateSize(balance);

    return 0;
}


void calculateSize(float array[]){

    int size = sizeof(array)/sizeof(array[0]);
    printf("Inside function         size: %d\n\n",size);
}

I am getting as result:
Outside function size: 4


Inside function size: 2



Does any of you know why this is happening? Also, which approach should I take to avoid this?

Thank you very much in advance,
Haecifer