Home » , , » Basic Discussion And Knowledge Building on "Array"

Basic Discussion And Knowledge Building on "Array"

Written By Unknown on Thursday, October 10, 2013 | 5:03 AM

Array :
Array is a type of variable collector which contain more than one variable with the same name.The way to declare array is as follow :
           Data_Type Array_Name [Size]

Data_Type means what type of array we will work with ( int, char.. etc ).How many variable or element will array contain is declared by the size of array.Like :
         
           int i [5]

Here i is an int type array and this array containing 5 variable or element.Array element starts from zero(0).

              i [0]

Here, i [0] is the first element of i [5] array.


Why We Use Array :
Lets think we will have to find out 30 days temperature individually and at the end of the month we will have to find the average temperature of that month.To do this we must need 30 variables like :

                 int first_day,second_day,third_day.....

but if we do this same task for 365 days than what will we do?Can we declare 365 variables easily?I don't think so....
In this case we can use " array " to compress our program and make it quit easy.

Array Declaration :
We can declare array of any data type.Like :
                                                                 int numb[25];
                                                                 char name[55];
                                                                 float value[20];
                                                                 double price[100];

Assigning Value In Array :
Array element could be used anywhere in the program as like an ordinary variable.Ex :
                                                                 int i [5];
                                                                 i[2] = 10;
                                                                 i[1] = i[2];
Array Initialization :
When array is declared,It can also be initialized too.Like :
                                                                 int numb [5]={1,2,3,4,5};

Watch The Program Carefully :
                                                                 #include<sthio.h>
                                                                 #include<conio.h>
                                                                  main()
                                                                  {
                                                                   static char cloud [] = {'C' ,'L', 'O', 'U', 'D'}
                                                                  int i;
                                                                  for(i=0;i<5;i++)
                                                                  printf("%c",cloud[i]);
                                                                  getch();
                                                                  }

OUTPUT :   CLOUD 
Share this article :

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Learn Programming - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger| Distributed by Rocking Templates