Introduction to Array by R4R Team

Array is the collection of the same data type.
-It is possible to create an array of any type.

Syntax-

type array_name[size];

Integer array:

Syntax-

int array_name[size];

-Here size defines the number of element an array have.

Character array:

-String is called as character array.

Syntax-

char array_name[size];

Example-
a=[1,2,3,4,5]
printf("%d",a[0]); //1
printf("%d",a[3]); //4


program-

#include< stdio.h>
int main()
{
int a[100],i;
printf("Enter 5 numbers\n");
//take input in array
for(i=0;i< 5;i++)
{
scanf("%d",&a[i]);
}
printf("Now we have 5 numbers in array,i.e,\n");
for(i=0;i< 5;i++)
{
printf("%d ",a[i]);
}
return 0;
}


output-

Enter 5 numbers
12 18 90 4 56
Now we have 5 numbers in array
i.e,
1218 90 4 56

-In this program, we define a array by a[100], where 100 shows the maximum number that can be store in array.
-But we put only 5 numbers in array and print them.




Leave a Comment:
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!