A program to pass a pointer to array as an argument to a function and print the content of an array.
A program to pass a pointer to array as an argument to a function and print the content of an array.
Codes
/*A program to pass a pointer to array as an argument to a function and print the content of an array*/
/*Programed by Jitendra Kr Yadav
10116
2Apr,2011*/
#include<stdio.h>
#include<conio.h>
void display(int* ,int );
void main()
{
int a[10],i,n,*ptr;
ptr=&a[0];
printf(“Enter the no of input to be taken:”);
scanf(“%d”,&n);
printf(“\n\nEnter the values:\n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf (“\n\nThe entered values for array is:\n\n “);
display(ptr,n);
getch();
}
void display(int *p,int n)
{
for(int i=0;i<n;i++)
printf(“%d\t”,*(p+i));
printf(“Press any key to continue…”);
}
Output
Enter the no of input to be taken: 5
Enter the values:
5
2
6
7
9
The entered values for array is:
5 2 6 7 9
Press any key to continue…