How to make your own computer to calculate the number of elements in the array sizeof

# include <stdio.h>
int main()
{
    int a[] = { 0,1,2,3,4,5,6,7,8,9,2,3,4,5,6 };
    int x = sizeof(a) / sizeof(a[0]);

    printf("数组中的元素有%d个",x);
    return 0;
}

sizeof entire array occupied content given size, in bytes
sizeof (a) / sizeof (a [0]) size sizeof (a [0]) are given in units of elements, obtained by dividing the number of elements in the array the number of
such write code, enter the number of code changes do not change, it will adapt to the program

Guess you like

Origin www.cnblogs.com/panghushalu/p/11786127.html