Arrays in C

In the section variable in C we have studied about variables. Variables are used to store single value.Multiple value cannot be stored by the variable.In your mind this question must have striked “How can you store multiple values in a single variable ?”. Its seems easier when you have to store less number of value . For example if you have to store marks scored in a subject by 5 students, you can say by using five variables this task could be done. But think how will you store marks of 100 students and print them. Now your answer may change.Its difficult to use 100 different variable for storing such datas.This type of storing can be done by using the concept of arrays.

What is an array?

It is a data type which can store the   multiple values of same type under a single name i.e. name of that particular array.

Why arrays?

  • It can store multiple value of same type.
  • It reduces the use of multiple variables.
  • Easy to perform operation on it.

Types of arrays:

  • One-Dimensional .
  • Multi-Dimensional.

ONE –DIMENSIONAL ARRAY:

One dimensional array is linear list.It is also known as vector.

Syntax:

example:

int arr[20];

  • Size of array must be  an unsigned integer number.
  • Size of array must not be variable, if it so it will lead to error.

Representation:

  • Continuous memory is allocated for array under a single name that is the name of array.

Arrays

                                                                                 (Picture taken from google)

  • Array name gives the address of first element of that array.
  • Every element of array having a index number and that index number stared from 0 and and end with size-1(as shown above).

Initialisation:

Initialisation of array can be done in two ways.It can be initialise at the time of array declaration or it can be also initialise later on by using loop or by accessing array index number.

example:

OUTPUT:

 

Two dimensional array:

2-D array is multidimensional array.Its representation looks like a matrix  so it also known as matrix .

syntax:

example:

Representation:

Representation of 2-D array looks like matrix but continuous block is allocated in memory for storing the elements.

Arrays

                                                                (picture taken from google)

Click here for related programs.
 

 

 

 

Leave a Reply