Array in C programming is a collection of the same type of data items, which is accessed by using common name. we use two types of arrays in C programming one-dimensional array and two-dimensional array.
#include<stdio.h>
#include<conio.h>
void main()
{ //'arr' is name of Array which length is 5 and assigning
int arr[5] = {2, 1, 3, 4, 63}; //values to it.
for(int i = 0; i < 5; i++) //loop looping from 0 to 5.
{
printf("%d\n", arr[i]); //and printing 'arr' Array Elements.
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{ //'arr' is name of Array which length is Not Defined and
int arr[] = {2, 1, 33, 4, 63}; //assigning values to it.
for(int i = 0; i < 5; i++) //loop looping from 0 to 5.
{
printf("%d\n", arr[i]); //and printing 'arr' Array Elements.
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h> //including Library for working with String.
void main()
{
char arr[] = {3, 2, 42, 66, 546, 6}; //'arr' is name of Array and assigning values.
for(int j = 0; j < strlen(arr); j++) //loop looping from 0 to
{ //length fo 'arr' Array.
printf(" %d", arr[j]); //printing 'arr' Array Elements.
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5]; //'arr' is name of Array and 5 is length of Array.
arr[0] = 1; //assigning Element to Every Index of 'arr' Array.
arr[1] = 5;
arr[2] = 65;
arr[3] = 0;
arr[4] = 13;
for(int i = 0; i < 5; i++)
{
printf("%d\n", arr[i]);
}
getch();
}