c - sizeof(array) / sizeof(int) -


this question has answer here:

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

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -