c - sizeof(array) / sizeof(int) -
this question has answer here:
- c sizeof passed array [duplicate] 7 answers
within function have declared array:
int char_count_array[118] = {0};
later on, pass array function , calculate following:
int xx = sizeof(char_count_array); int xy = sizeof(char_count_array)/sizeof(int);
however, result is: xx = 4 xy = 1
i thought getting: xx = 472(118 * 4) xy = 118 (472 / 4).
would know doing wrong here?
if passing function, it's going in int*
instead of int[118]
. sizeof
returning size of pointer. when pass c arrays functions, it's conventional pass number of elements.
my_func( arr, sizeof(arr)/sizeof(arr[0]) );
Comments
Post a Comment