Array in C

The collection of values having the same data type is called an array.

There are two types of array.

  1. Single dimension array
  2. Multi dimension array

Single dimension array

#include<stdio.h>
#include<conio.h>
int main(){
	int x[5]={10, 20, 30, 40, 50};
	int i;
	for(i=0; i<5; i++){
		printf("%d \n", x[i]);
	}
	getch();
	return 0;
}

Multi dimension array

#include<stdio.h>
#include<conio.h>
int main(){
	int x[2][5]={ 
			{10, 20, 30, 40, 50},
			{60, 70, 80, 90, 100}
		};
	int row, col;
	for(row=0; row<2; row++){
		for(col=0; col<5; col++){
			printf("%d ", x[row][col]);
		}
		printf("\n");
	}
	getch();
	return 0;
}
© 2016 - 2022, All Rights are Reserved.