Can i do this?
return !(s == 1000);
I tested it and if it is false it returns 0, but if it is true it returns nothing... Why doesn't it return 1?
Can i do this?
return !(s == 1000);
I tested it and if it is false it returns 0, but if it is true it returns nothing... Why doesn't it return 1?
It does return 1. It will return 0 when s is 1000 and 1 otherwise.
In this instance it would be vastly more readable to say return s != 1000;.
a return statment will ALWAYS return something. The code you have above will return either 0 or 1 by definition of the C "boolean" values - even in standard C that doesn't have the "bool" type.
Perhaps you can produce a small compilable example - but I guarantee you that the function returns and will return a value, whatever you do in a return statement [1] - the return value may be RUBBISH, but it will return SOMETHING that is compatible with the return type of the function.
[1] For the pedants - it is of course also possible to write a return-statement that calls a function that never returns - in this case, the return statement doesn't complete, because the called function never returns. This is something other than what Milhas seems to indicate, which is that the function returns but it doesn't give the correct value back.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Code:#include <stdio.h> #include <stdlib.h> int test(int s) { return !(s==1000); } int main(void) { printf("%i\n", test(999)); printf("%i\n", test(1000)); }Code:silverlx:~$ ./temp2 1 0
Please post a small compilable program, and no, it's not returning NULL for true - it will return the integer value 1 (assuming the return type is int).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Your right, it returns 1.
Thanks for showing it to me