2. Types of Array
● Linear Array
● Non-Linear Array
Linear Array
This type of array is also called one Dimensional Array. This is also called list array. Another name of linear array is
called single-dimensional array. These array are of ladder type. In the linear array only one subscript is used. It is written either in row
or in column form.
The syntax to define or declare linear array is:
data-type arrary-name[size];
3. Basic Array Operations
Following are the basic operations supported by an array.
● Traverse − print all the array elements one by one.
● Insertion − Adds an element at the given index.
● Deletion − Deletes an element at the given index.
● Search − Searches an element using the given index or by the value.
4. Traverse Operation
This operation is to traverse through the elements of an array.
Example: Following program traverses and prints the elements of an array:
#include <stdio.h>
main() {
int LA[] = {1,3,5,7,8};
int n = 5;
int i;
printf("The original array elements are :n");
for(i = 0; i<n; i++) {
printf("LA[%d] = %d n", i, LA[i]); }
}
5. When we compile and execute the above program, it produces the following result :
The original array elements are :
LA[0] = 1
LA[1] = 3
LA[2] = 5
LA[3] = 7
LA[4] = 8
Insertion Operation
Insert operation is to insert one or more data elements into an array. Based on the requirement, a new element can be
added at the beginning, end, or any given index of array.
6. Insertion at the end of an Array:
#include <stdio.h>
#define MAX 5
void main() {
int array[MAX] = {1, 2, 3, 4};
int N = 4, i = 0, value = 5;
printf("Printing array before insertion −n");
for(i = 0; i < N; i++)
printf("array[%d] = %d n", i, array[i]);
array[N] = value;
N++;
printf("Printing array after insertion −n");
for(i = 0; i < N; i++)
printf("array[%d] = %dn", i, array[i]);
}
8. Non-Linear Array
Array of having different dimensions or n subscript is in the form of Non-linear array. Non-linear array are further of n
different types as:
(a) Two Dimensional Array
(b) Three Dimensional Array
............................
(n) N-Dimensional Array
9. Two-Dimensional Array
These arrays are also called double dimensional array. Another name of two-dimensional array is Tabular or
Rectangular Array. These array are in row and column form, so these are also called Row-Column array or square array.
The syntax to define or declare two dimensional array is as:
data-type arrary-name[row size][column size];
For example, some of the valid one dimensional array declaration statements are written as below:
int a[10][10];
float f[50][50];
char n[20][20];
11. Initializing Three-Dimensional Array: Initialization in Three-Dimensional array is same as that of Two-dimensional arrays.
The difference is as the number of dimension increases so the number of nested braces will also increase.
Method 1:
int x[2][3][4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23};
Better Method:
int x[2][3][4] = {
{ {0,1,2,3}, {4,5,6,7}, {8,9,10,11} },
{ {12,13,14,15}, {16,17,18,19}, {20,21,22,23} }
};