Read and Display Array elements in C

This “Read and Display Array elements in C” page explains clearly how to read elements, process elements and display elements using loops in C language.


 

  • Array elements can be processed using loops.
  • It is complex to process elements without iterators.

 

Printing default values of Local array variable :
#include<stdio.h>
void main()
{
int arr[5],i;
for(i=0 ; i<5 ; i++)
{
printf(“%d\n”,arr[i]);
}
}

 

Printing default values of Local array variable :
#include<stdio.h>
void main()
{
int arr[5],i;
printf(“Enter 5 elements : “);
for(i=0 ; i<5 ; i++)
{
scanf(“%d”, &arr[i]);
}
printf(“Array elements are : \n”);
for(i=0 ; i<5 ; i++)
{
printf(“%d\n”,arr[i]);
}
}

 

Printing consecutive references of array elements : 
#include<stdio.h>
void main()
{
int arr[5]={10,20,30,40,50}, i;
printf(“Array elements with memory locations : \n”);
for(i=0 ; i<5 ; i++)
{
printf(“arr[%d] : %d \t address : %u \n”, i, arr[i], &arr[i]);
}
}

Share this