简体   繁体   中英

control reaches end of non-void function. How to solve this?

solution.c: In function 'subtractProductAndSum' Line 31: Char 1: error: control reaches end of non-void function [-Werror=return-type] [solution.c] } ^ cc1: some warnings being treated as errors

int subtractProductAndSum(int n){

    int k , j=n , count=0 , add=0 , multiply=1;
  
    while(j>0){
    
        j=j/10;
        count++;
    
    }

    int p=count;
    int arr[p];
        
    while(n>0){
        k=n%10;
        n=n/10;
        
        if(p>0){        
            arr[p-1]=k;
            p--;
        }
    }
    for(int i = 0; i <count ;i++){
      add=add+arr[i];
      multiply=multiply*arr[i];
    }
    
    int t=multiply-add;
    printf("%d", t);
    
}

Your function is declared as an int, meaning it's expected to return an int. Your function doesn't return an int -- in fact, it doesn't return anything.

As @Retired Ninja said, you need to figure out what you want your function to return, and add an appropriate return statement.

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