Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Addition of an array elements in c

/ 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);
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading