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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -