Letting the compiler count elements for array element - C Array

C examples for Array:Introduction

Description

Letting the compiler count elements for array element

Demo Code

#include <stdio.h>
int main(void)
{
    const int days[] = {31,28,31,30,31,30,31,31,30,31};
    int index;/* w  w w. j  a v  a2  s.  c  om*/
    
    for (index = 0; index < sizeof days / sizeof days[0]; index++)
        printf("Month %2d has %d days.\n", index +1,
               days[index]);
    
    return 0;
}

Result


Related Tutorials