Write a program to display elements of an array using pointer.

C File =>


/* Write a program to display elements of an array using pointer. */


#include<stdio.h>
int main() {
int num[30],n,i,sum;
//declaring pointer to array
int (*p)[30]=&num;
printf("\n Enter how many elements :");
scanf("%d",&n);
printf("\n Accepting data :\n");
for(i=0;i<n;i++)
{
   printf("\n Enter number%d:",i+1);
   scanf("%d",&num[i]);
}

printf("\n Array elements are:\n");
//displaying array elements using pointer
for(i=0;i<n;i++)
 printf("%d\t",(*p)[i]);
return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.