C - Initializing an array

Introduction

The initialization of array requires a special format, similar to this statement:

int highscore[] = { 750, 699, 675 }; 

The number in the square brackets isn't necessary when you initialize an array.

The compiler can count the elements and configure the array automatically.

Demo

#include <stdio.h>

int main()/*  ww w  . j  av  a 2 s.  c  om*/
{
    float marketclose[] = { 1.06, 8.62, 4.14, 5.11, 3.06 };
    int day;

    puts("Stock Market Close");
    for(day=0;day<5;day++)
        printf("Day %d: %.2f\n",day+1,marketclose[day]);
    return(0);
}

Result

Related Topic