
Initialization of Arrays Using Functions 519
12.9 Program to pass entire elements of an array to a function.
#include<iostream.h>
#include<conio.h>
void show(int *,int);
void main()
{
int num[5]={1,2,3,4,5},i;
clrscr();
cout<<“\nElements of the array are as follows:”;
show(&num[0],5);
}
void show(int *x,int y)
{
int i;
for(i=0;i<=y-1;i++)
{
cout<<“ ”<<*x;
x++;
}
}
OUTPUT
Elements of the array are as follows: 1 2 3 4 5
Explanation: In the above program, the address of the zeroth element, that is, &num[0], is
passed to the function show(). The for loop is used to access the array elements using point-
ers. The show() function is invoked with