Pointer Using Array in C Programming


#include<stdio.h>
#include<conio.h>

int array_sum(array,n)
int array[];
int n;
{
    int sum=0,*ptr;
    int *array_end=array+n;
    ptr=array;
    for(;ptr<array_end;++ptr)    //or for(ptr=array;ptr<array_end;++ptr)
    sum+=*ptr;
    return (sum);
}

main()
{
      static int values[10]={3, 7, -9, 3, 6, -1, 7, 9, 1, -5};
      printf("The sum is %d\n",array_sum(values,10));
      getch();
}

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples