how to write an array in c code example

Example 1: array loop in c

int i, array[5]= {1, 2, 3, 4, 5};
for(i=0 ; i<5 ; i++)
{
	printf("%d", array[i]) ;
}

Example 2: c program for array

// Array declaration by specifying size 
int arr1[10]; 
  
// With recent C/C++ versions, we can also 
// declare an array of user specified size 
int n = 10; 
int arr2[n];

Example 3: array of array in c

int a[3][4] = {  
   {0, 1, 2, 3} ,   /*  initializers for row indexed by 0 */
   {4, 5, 6, 7} ,   /*  initializers for row indexed by 1 */
   {8, 9, 10, 11}   /*  initializers for row indexed by 2 */
};

Tags: