
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 1
This page cannot be seen from the preview
Don't miss anything!

#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(); }