c - Length of an array using sizeof -


i trying determine length of array using sizeof function.

my code looks this:

int n; n = sizeof(a)/sizeof(a[0]); 

i keep getting warning saying type inconsistent. understand how fix problem?

the error telling a function parameter, , sizeof(a) return size of int* instead of actual size of array. reason because function parameters of array types same thing pointers (so parameter of type int[] parameter of type int*) , size specified in array type information reader, not compiler enforces.

the sizeof(a)/sizeof(a[0]) trick suitable use macros, not should writing in non-macro code, because if you're in context it's possible statically know length of array (e.g. didn't come function parameter) should know without having compute it.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -