Array Of C
Arrays a kind of data structure that can store a fixed-size sequential collection
of elements of the same type. An array is used to store a collection of data,
but it is often more useful to think of an array as a collection of variables o
the same type.
Types Of Array :
1.One Diamational Array
2.Two Dimensional Array
3.Multi Diamational Array
Declaration Array
To declare an array in C, a programmer specifies the type of the elements
and the number of elements required by an array as follows −
type arrayName [ arraySize ];
1.Single Dimensional Array :
Single or One Dimensional array is used to represent and store data in a linear form.
Array having only one subscript variable is called One-Dimensional array
It is also called as Single Dimensional Array or Linear Array.
Syntax:
[size];
Example :
int iarr[3] = {2, 3, 4};
char carr[20] = "c4learn" ;
float farr[3] = {12.5,13.5,14.5} ;
2.Two Dimensional Array :
The two dimensional array in C language is represented in the form of rows and columns,
also known as matrix. It is also known as array of arrays or list of arrays.
The two dimensional, three dimensional or other dimensional arrays are also known as multidimensional arrays.
Syntax:
Example :
#include <stdio.h>
#include <conio.h>
void main(){
int i=0,j=0;
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
clrscr();
//traversing 2D array
for(i=0;i<4;i++){
for(j=0;j<3;j++){
printf("arr[%d] [%d] = %d \n",i,j,arr[i][j]);
}//end of j
}//end of i
getch();
}
3. Multi Dimensional Array :
Array having more than one subscript variable is called Multi-Dimensional array.
Multi Dimensional Array is also called as Matrix.
Syntax:
< [row_subscript][column-subscript];
Example :
int a[3][3] = { 1,2,3
5,6,7
8,9,0 };
<< PREVIEW >>
<< NEXT >>
Comments
Post a Comment