Array
An array is a collection of similar data type which occupies
continuous location on memory. Array is useful bulk process is required on
similar data type. Name of array is a constant pointer which point first
element of array. Elements of array are access through index number. Index
donates numeric position of data in an array. Index start with zero and last
element less than one from the specified size of array.
Syntaxt :
Data_type arr_name[size_int]
Address of array element is calculated mathematically i.e.
index added to base address . address
jump as per the data type size. For example int array will jump 2 position
because int takes 2 byte, character array will jump one position because its
takes 1 byte storage size. You can perform only two operation in array pointer
add and subtract.
Example
#include<stdio.h>
#include<conio.h>
/*============================
Girfa Student Help
Introduction of array
==============================*/
void main()
{
int ar1[4],i;
int ar2[]={1,2,3,4}; /*
declare and initialiaze */
clrscr();
/*
input print from keyboad demo */
for(i=0;i<4;i++)
{
printf("Enter Number of %d position>> ",i+1);
scanf("%d",&ar1[i]);
}
for(i=0;i<4;i++)
{
printf("%d\t",ar1[i]);
}
getch();
}
Advantage
- Array is better option to process bulk data of similar type.
- Accessing element of an array is very easy using index number.
- Search can be performing in array.
- Matric can be implemented using array which helps to handle complicated application.
- String processing in C language is achieved through array.
- Different types of sorting algorithm can be implemented through array.
·
Disadvantage
- Array allocates static memory location, which turn into wastage of memory when data is less than allocated size.
- Static memory allocation is fix which allocated at compile time. So it cannot be modified later.
No comments:
Post a Comment