Sunday, February 7, 2010

C Programming - logical value of TRUE and FALSE?

In C programming, will there be a case whereby the logical value is 0 when the statement is TRUE and the logical value is 1 when the statement is FALSE? Can someone give some examples if there's such cases.C Programming - logical value of TRUE and FALSE?
strcmp returns 0 if the compared strings are identical.


strcmp returns %26gt; 0 if the compared strings are different.





#define TRUE 1


#define FALSE 0





if (FALSE) {


/* This code will never be reached */


}





int i = 0;


while (i == FALSE) {


/* Here we have an endless loop */


}








if (TRUE) {


/* This code will always be reached */


}





int i = 0;


while (i != TRUE) {


/ * this code loop until i becomes 1 */


}C Programming - logical value of TRUE and FALSE?
C does not have a boolean operator. There is no ';true'; or ';false'; in C.





You can have anything equal to true or false. You can make a char 't' be true and 'f' be false, an int '0' be false, '1' be true, '1' be false, '0' be true, '1374.274' be false, '2479.983' be true. C won't know the difference.

No comments:

Post a Comment