• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #52
      /* day_mon1.c -- prints the days for each month */
      #include <stdio.h>
      #define MONTHS 12
      int main(void)
      int days[MONTHS] = {31,28,31,30,31,30,31,31,30,31,30,31};
      int index;
      for (index = 0; index < MONTHS; index++)
      printf("Month %d has %2d days.\n", index +1,
      return 0;

      What I could not understand is how MONTHS values are assigned to index. No where in the code I could see index = values of MONTHS (or something similar).

      for (index = 0; index < MONTHS; index++)

      For loop above only seems to indicate index starts counting with 0 and continues till 11. But how it is taken granted that days [index] will be counter for the values of days[MONTHS].

      On second look, it appears that days variable (or should I call array? if days is the name of array, what should I call MONTHS?) takes {31,28,31,30,31,30,31,31,30,31,30,31}; Next, these 12 values can be assigned to any other named array, which in this case index.



    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top