Retrieve Array Length

To retrieve array length, we can use the following trick:

int array[] = {1,2,3,4,4,6,7,7};
int length = sizeof(array) / sizeof(array[0]);

Or we can define a Macro to get length:

#include <stdio.h>
#define getLength(array) (sizeof(array) / sizeof(array[0]))

int main() {
    int array[] = {1,2,3,4,5,6,7,8,9,10};
    printf("%lu\n", getLength(array));
}

[!danger]
You cannot use a function here because explained in Pass array to function. Therefore, we need to use a Macro.