Array
Syntax :
Data_Type Array_Name[Size];
A collection or group of similar type of datatypes.
Means if you create an array of integer type that means it can hold only integer values.
An array can be..
1. Integer type
2. Float type
3. Character type
4. Pointer type ( to store pointers)
In C we use array to create string or we can say an array of character is treated as a string.
Note: C does not provide any exception or error on array out of bound.
That means if you try to insert values more than the specified size of your array in program, during run time it will accept all. But it holds only up to its actual size.
* Array always occupy continuous space while allocation in memory.
-----------------------------------------------------------------------
Just a basic program to create an integer type array with size 10 and inserting values through for loop.
/*Program to create an integer array */
#include<conio.h>
void main()
{
int a[10]; //integer type array
int i;
clrscr();
printf("\nEnter 5 numbers:\n");
//Inserting values into array
for(i=0;i<5;i++)
{
printf("\nElement %d =>",i+1);
scanf("%d",&a[i]);
}
getch();
}
No comments:
Post a Comment