简体   繁体   中英

error: Void Value not ignored as it ought to be, C programming

I just have a really quick question to ask of all of you. I keep having the problem in my C code, where it says

error: void value not ignored as it ought to be

The problem where my code is happening is in the call statement in order for the function to run

m = myMax1(a,len,m);

and the function that is void where this is coming from is as below:

void myMax1( int *arr, int *max, int n )
{
     max = arr[0];
     for(n = 0; n < max; n++)
     {
         if(arr[n]>max)
         {
             max = arr[n];
         }
     }
}

If you have any solutions, please let me know! Thank you very much!

Your function is not returning anything but you're assigning the return value to a variable m . If you're calling it just for side effects, don't assing the return value to anything.

When a function returns void , you cannot use:

m = myMax1(a,len,m);

You can use:

myMax1(a,len,m);

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