Array in C Language Tutorial Notes Study Material with Examples

Array in C Language Tutorial Notes Study Material with Examples

Array

It is a collection of similar elements (having same data type). For an array

of 100 elements, the first element’s index is zero ‘0’ and the last index will

be 99. This indexed access makes it very convenient to loop through each

element of array. Array elements occupy contiguous memory locations.

Array in C Language Tutorial Notes Study Material with Examples
Array in C Language Tutorial Notes Study Material with Examples

 A [0] = a

A [1] = b

 A [7] = h

Multi Dimensional Array

In C language, one can have arrays of any dimensions. Let us consider a

3 x 3 matrix.

 

Array in C Language Tutorial Notes Study Material with Examples
Array in C Language Tutorial Notes Study Material with Examples

3 x 3 matrix for multi dimensional array

To access the particular element from the array, we have to use two subscripts; one for row number and other for column number. The notation is of the form a [i] [1], where i starlets for row subscripts and j stands for column subscripts.

We can also define and initialize the array as follows int values [3] [4] = 

(11, 2, 3, 4,1

( 5 , 6, 7, 81

(9, 10, 11, 121

);

OR

int values [3] [4]

                            = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

A simple program using array

# include  <stdio.h> void main ( )

{

a [ i ]

Subscripted           Subscript

Variable

int ave, sum= 0;

int i;

int marks [10];                                   // array declaration

for (i =0; i <= 9; i + +)

{

printf (“\n Enter marks”);

scanf (“%d”, &marks [1]); // store data in array

}

   for (i = 0; i <= 9; i + +)

sum= sum+ marks [I]; avg= sum/30;

printf (“1n avg-marks= %d”, avg);


Importance of Turing Machine Tutorial Notes Study Material with Examples

Follow Us on Social Platforms to get Updated : twiter,  facebookGoogle Plus

Learn Turing Machine in Handbook Series:  Click here 

Leave a Reply

Your email address will not be published. Required fields are marked *