简体   繁体   中英

Previous declaration and conflicting types

Ive got a problem. I cant compile my program even though everything seems fine. It comes up with those errors":1.c:6:5: error: conflicting types for 'sumaa' int sumaa(int tab[],int a){ ^~~~~ 1.c:3:5: note: previous declaration of 'sumaa' was here int sumaa(int,int); ^~~~~ I dont know why. Here's the code:

#include<stdio.h>

int sumaa(int,int);
int suma(int*,int*);

int sumaa(int tab[],int a){
    int sum = 0;
    for(int i= 0; i<a;i++)
        sum+= tab[i];
    return sum;
}

int suma(int* a,int* b){
    int  suma = 0;
    int* pt;
    for (pt = a; pt != b; pt++)
        suma+=*pt;
    return suma;
}

int main()
{
    int n;
    scanf("%d",&n);
    int tab[n];
    for(int i = 0; i<n;i++){
        scanf("%d",&tab[i]);
    }
    sumaa(tab,n);
    suma(tab,tab+n);
    return 0;
}

You have to make the first parameter as an array in the prototype.

int sumaa(int*,int);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM