Initializing an array using for loop : Array Initializing « Array « C Tutorial






#include <stdio.h>

int main()
{
   int n[ 10 ]; 
   int i; 
   
   /* initialize elements of array n to 0 */
   for ( i = 0; i < 10; i++ ) {
      n[ i ] = 0;
   }
   
   printf( "%s%13s\n", "Element", "Value" );

   for ( i = 0; i < 10; i++ ) {
      printf( "%7d%13d\n", i, n[ i ] );
   } 

   return 0;

}
Element        Value
      0            0
      1            0
      2            0
      3            0
      4            0
      5            0
      6            0
      7            0
      8            0
      9            0








7.2.Array Initializing
7.2.1.Initializing an array in declaration
7.2.2.Initializing an array using for loop
7.2.3.Initialize the elements of array to the even integers from 2 to 20