Traversing an array means to access each and very element of array .It can be accessed using for loops.The data stored in array can be travesred by using for loop and the elements can be accessed by incerement the for loop. The loop starts to traverse array from the start of the array and continue to traverse array until the for lopp continues its execution until the for loop ends.UIn the program below the elements are stored in an array and are travesred using for loop . The loop prints all the elements of array using traversing.
Program for traversing an array.
#include<iostream.h>
#include<conio.h>
void main()
{
int data[5]={1,2,3,4,5};
int i;
clrscr();
cout<<""Elements of array Data are";
for(i=0;i<=4;i++)
{
cout<<data[i];
}
getch();
}
No comments:
Post a Comment