C does not have a boolean data type...

  • The C programming language does not have boolean values nor a boolean data type

  • C programs typically uses the int data type to store boolean values

  • How the C compiler interpret int values as boolean values:

      int value            interpreted as
     =======================================
       0                     false
       a non-zero value      true
    

  • Even floating point values can be interpreted as boolean values:

      float/double value     interpreted as
     =======================================
       0.0                   false
       a non-zero value      true
    

C program that shows how numbers are interpreted as boolean values in C

int main( int argc, char* argv[] )
{
   char x = 0; // false - char is usually used as boolean variables
   char y = 4; // true

   if ( x )
      printf("x = %d is true\n", x);
   else
      printf("x = %d is false\n", x);

   if ( y )
      printf("y = %d is true\n", y);
   else
      printf("y = %d is false\n", y);

   if ( 0.1 )
      printf("value 0.1 is true\n");
   else
      printf("value 0.1 is false\n");

   if ( 0.0 )
      printf("value 0.0 is true\n");
   else
      printf("value 0.0 is false\n");
}

DEMO: demo/C/set1/logic1a.c