what is array in c language
An array is a data structure that contains a series of elements . The array is used to store the collection of data. but it is mostly more useful to think about an array as a collection of variables of the same type .The elements are all of the related data type in .The Array is a collection of data items in the sequential form all the same types, accessed using a related name in the array .one dimensional array is like the single link list and the two dimensional array is like a table mean in two dimensional array rows and columns are shown.in array the data is stored in the different indexes but in sequence or series.There are different types of array.how to declare an array or method of declaring an array.The array is always start with the index (o).
in the above diagram there are six elements.which can be declared in the following shape.
array name[5] if we use the loop and conditions we can also do other wise only write simple.
Array declaration
The array declaration is as follow
Datatype[ ] array name;
int [ ] marks= new int[ ];
in the above line the int is a data type and marks is a array name and =new int [ ]; is used to print the value which we declare the value
- The datatype can be int,float,char etc, is used to store the element of an array.
- The brackets [ ] are used to specify the array size.
- The array name specify the name of the array which we declare for execution.
How to find the size of an array
To check the size of the array in the bytes (one byte is contain on 8 bits) , you can use the sizeof operator. int a[17]; The sizeof() operator will only work for the fixed size of an array.The sizeof() is based on the compilation time information.The sizeof operator is used to to give the size of the variable which is declared in the array.
Types of the array
There are different types of an array these are.
- one dimensional array
- Two dimensional array
- multi dimensional array
one dimensional array
The one dimensional array is also called single dimensional array is the type of array. Accessing its elements involves the single subscript which can be either represent a row or column index.
As an example consider the C declaration int marks10];
In the above given example the array is contained with the 10 elements of any value available to the int data type. In the C, the array element scale are from 0 to 9 indexes because the array is always start form 0 index.
Two dimensional array
The array is known as two dimensional array . The two dimensional array in C programming is also known as matrix or table which contain on the rows and columns. A matrix can be represented as a table of rows and columns. Before we discuss more about two Dimensional array.The example of the two dimensional array is as follows.
include<stdio.h>
include<conio.h>
void main( )
{
int marks[4][5];
int i,j;
for (i=o;i<5;i++) {
for (j=0;j<5;j++) {
printf (” Enter the value for marks [%d][%d] :”,i,j);
scanf (“%d”, &marks[i][j]);
}
}