Hello friends how are you, today in this blog i will teach you what is Array, syntax of Array, how Array works and many programs of Array in a very simple way.
Let's start
1.It is a collection of data of same data type.
2.It is used to store group of data simultaneously.
3.It can store data of same data type means an integer array can store only integer value ,character array can store only character value and so on.
4.We can not fetch data from array directly therefore we use index point.
5.The indexing of array always start with 0.
6.Index value is always an integer number.
7.Array may be of any data type like int, char, float etc.
👉Syntax
int a[5]={ 45,23,89,12,78 };
int a[5]; a[0]=45; a[1]=23; a[2]=89; a[3]=12; a[4]=78;
#include<stdio.h> int main() { int a[5]={ 45,23,89,12,78 }; printf("value at a[0]=%d\n",a[0]); printf("value at a[1]=%d\n",a[1]); printf("value at a[2]=%d\n",a[2]); printf("value at a[3]=%d\n",a[3]); printf("value at a[4]=%d\n",a[4]); } ### Output ### value at a[0]=45 value at a[1]=23 value at a[2]=89 value at a[3]=12 value at a[4]=78
#include<stdio.h> int main() { int a[5]={ 45,23,89,12,78 }; for(int i=0;i<=4;i++) { printf("value at a[%d]=%d\n",i,a[i]); } } /* ### Output ### value at a[0]=45 value at a[1]=23 value at a[2]=89 value at a[3]=12 value at a[4]=78 */
#include<stdio.h> int main() { int a[3];//declaring array printf("Enter element 1="); scanf("%d",&a[0]);//taking input at index 0 printf("Enter element 2="); scanf("%d",&a[1]);//taking input at index 1 printf("Enter element 3="); scanf("%d",&a[2]);//taking input at index 2 for(int i=0;i<=2;i++) { printf("value at a[%d]=%d\n",i,a[i]); } } /* ### Output ### Enter element 1=12 Enter element 2=45 Enter element 3=17 value at a[0]=12 value at a[1]=45 value at a[2]=17 */
#include<stdio.h> int main() { int a[3];//declaring array for(int j=0;j<=2;j++) { printf("Enter element %d=",(j+1)); scanf("%d",&a[j]);//taking user input } for(int i=0;i<=2;i++) { printf("value at a[%d]=%d\n",i,a[i]); } } /* ### Output ### Enter element 1=12 Enter element 2=45 Enter element 3=17 value at a[0]=12 value at a[1]=45 value at a[2]=17 */
0 Comments