C program to print the length of a given array without using sizeof
kw.c
#include <stdio.h>
int main()
{
    int min, max;
    int arr[5] = {100, 15, 8, 45, 93};
    int length = *(&arr + 1) - arr;
    printf("Length of a given array is %d", length);
    return 0;
}
Output
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out Length of a given array is 5 kodingwindow@kw:~$
Advertisement