Write a program to find the sum of the elements contained in an integer array using pointers to array.

#include<stdio.h>
#include<conio.h>
main()
{
    clrscr();
    int *p,sum=0,i;
    int x[5]={5,9,6,3,7};
    i=0;
    p=x;/*initializing with base address of x */
    printf("Element Value address of x\n\n ");
    while(i<5)
    {
        printf("x[%d]%d%u\n",i,*p,p);
        sum=sum+*p; /*accessing array element*/
        i++;
        p++;    /*incrementing pointer*/
    }
    printf("\n sum =%d\n",sum);
    getch();
}
Next Post Previous Post
No Comment
Add Comment
comment url