#1

0 is false and 1 is true, what about this -1 and if there is more tell me pls
Reply
#2

Whatever you want it to be usually this is used to denote an invalid value when adding an element to an dynamic array for example the array was full so you return -1 since 0 is a valid value.
Reply
#3

If you are testing for truth, 0 is "false", and anything other than zero is "true".

Код:
if (0) {
    /*
        this code does not run, since 0 is a "false" value
        ...
    */
}

if (-1) {
    /*
        this code *does* run, since -1 is a "true" value
        ...
    */
}
If you want to do a different test, you need to specify it. To take Pottus's example above, if you have a function that returns a value greater than or equal to 0 on success, and returns -1 on failure:

Код:
if (myFunction() > -1) {
    // this will run if the function is successful
}
It all depends on the context.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)