Unit - 3@array
Unit - 3@array
1
Array
• Array is defined as the collection of similar type of data items
stored at contiguous memory locations. that are referenced by a
common name.
• Instead of that, we can define an array which can store the marks
in each subject at the contiguous memory locations.
2
Advantage of Array
3
Disadvantage of C Array
Fixed Size:
Whatever size, we define at the time of
declaration of the array, we can't exceed the limit.
4
Types
One-Dimensional array(1-D)
Two-Dimensional array(2-D)
5
How to declare an array
• Syntax:
datatype array_name[size];
• Syntax:
data_type array_name[size]={values};
7
Example
8
#include<stdio.h>
void main()
{
int a[5]={10,20,30,40,50},i;
clrscr();
for(i=0;i<5;i++)
{
printf("\nThe value in a[%d] is %d",i,a[i]);
}
getch();
} OUTPUT
14