C - Arrays

An array is a data structure which can be used to store set of values with similar data types.
In C , arrays can be devided into two types.

  1. Single Dimensional Arrays
  2. Multi Dimensional Arrays

Single Dimensional Arrays

The declaration form of single dimensional array is,

data_type array_name[size];

Ex:
int number[5];
float number[5];

In a array index is starting from 0. Therefore the last index is always equals to (size - 1)
In the above examples the size is defined to 5 therefore the last index is 4.

We can assign values to relative indexes as below.
number[0]=10;
number[1]=4;
number[2]=5;
number[3]=47;
number[4]=43;

Also we can ask users to input numbers for the array and we can display the entered numbers.
Let's see how that can happen from a example.


Output of the above code.

 Multi Dimensional Arrays

In multi dimensional arrays, we can find different number of rows and columns.
In below I have  explained how to declare a 3 x 4 matrix.

 no of rows
         ↑
int a[3][4];←no of columns
  ↑
 data type

Ex:












Comments

Popular posts from this blog

Programming with Java

C- Control Structures

C - Functions