How do get the array length?

@boguz:

But it is kind of useless if i already know the size of the array anyway.

It's real purpose is to make changing things easier in the code, and to automatically adjust the count if you cross platform. For example, You often see things like:

int myArray[10];
// ...a bunch of code...

for (i = 0; i < 10; i++) {
   // for loop code...

Now if you decide to change the size of the array, you must go through the entire source file and change every instance of the constant used in the second expression of the for loop. Using the macro automatically adjusts the loop if you use:

int myArray[10];
// ...a bunch of code...

for (i = 0; i < HowBigIsThisArray(myArray); i++) {
   // for loop code...

Now, if you change the size of the array, it's automatically adjusted throughout the program.

The other advantage is that the macro can be used with any data type, so HowBigIsThisArray() can be passed a float, long, int, or byte array and it returns the correct length. If you move the code to a platform where an int is 4 bytes rather than 2, it still returns the correct number.

In short, the marco reduces the number of things you might otherwise have to change and, as a general rule, the fewer edits you make to working code, the better.