Program to show use of pointer with array in c.


main()
{
int *p, sum=0, i=0;
int x[5]={3,4,7,8,5};
clrscr();
p=x;
printf("Element Value Address\n\n");
while(i<5)
{
printf(" x[%d] %d %u\n",i,*p,p);
sum=sum+*p;
i++, p++;
}
printf("\nSum: %d",sum);
printf("\n&x[0]: %u",&x[0]);
printf("\np: %u",p);
getch();
}

No comments:

Post a Comment