Home > Net >  Addition of an array elements in c
Addition of an array elements in c

Time:10-09

/ I am trying to add array elements in c using myfun() but compiler shows warning [Warning] passing argument 1 of 'myfun' from incompatible pointer type /

#include<stdio.h>
void myfun(int*);
void main()
{
    int a[10] = {1,2,3,4,5,6,7,8,9,11};
    printf("Array Elements are : ");
    myfun(&a);
}
void myfun(int* a)
{
    int i;
    int sum = 0;
    for(i=0;i<10;i  )
    {
        printf("\t%d\t",a[i]);
        sum = sum   a[i];
    }   
    printf("\n\nSum : %d",sum);
}

CodePudding user response:

a already has type convertable to int*, you don't need use &a

  • Related