C++ Array Traversal Program, Exercises of Data Structures and Algorithms

A simple c++ program that uses pointers to traverse and print the elements of an array. The program initializes an integer array 'a' of size 10, assigns the address of the first element to pointer 'p', and then uses two for loops to iterate through the array and print its elements using cout. The first loop prints the elements in a new line, while the second loop prints them in the same line, separated by a space. The getch() function is used to pause the console window before closing.

Typology: Exercises

2011/2012

Uploaded on 07/30/2012

dhanvantari
dhanvantari 🇮🇳

2

(2)

45 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include<conio.h>
#include<iostream.h>
void main (void)
{
int a[10]={1,2,3,4,5,6,7,8,9,10};
int *p;
clrscr();
for (p=&a[0];p<&a[10];p++)
{
cout<<" "<<*p;
}
cout<<"\n\n\n";
p=&a[0];
for (int i=0;i<10;i++)
{
cout<<" "<<*p;
p++;
}
getch();
}
docsity.com

Partial preview of the text

Download C++ Array Traversal Program and more Exercises Data Structures and Algorithms in PDF only on Docsity!

#include<conio.h> #include<iostream.h> void main (void) { int a[10]={1,2,3,4,5,6,7,8,9,10}; int p; clrscr(); for (p=&a[0];p<&a[10];p++) { cout<<" "<<p; } cout<<"\n\n\n"; p=&a[0]; for (int i=0;i<10;i++) { cout<<" "<<*p; p++; } getch(); }

docsity.com