Skip to content

C_Booleans.c

SunilOS edited this page Sep 9, 2024 · 1 revision

C_Booleans.c

#include <stdio.h>   // Includes the standard input/output library, needed for printf function
#include <stdbool.h> // Includes the library to use boolean data types like 'bool', 'true', and 'false'

int main() {
    bool isTrue = true;  // Declares a boolean variable 'isTrue' and assigns it the value 'true'
    
    // Prints the boolean value (in C, 'true' is represented as 1 and 'false' as 0)
    printf("Boolean value: %d\n", isTrue);
    
    return 0;  // Returns 0 to indicate successful execution
}

Explanation:

  • #include <stdbool.h>: Includes the stdbool.h header, which provides boolean types (bool, true, false).
  • bool isTrue = true;: Declares a boolean variable isTrue and assigns the value true (represented as 1).
  • printf("Boolean value: %d\n", isTrue);: Prints the boolean value. In C, true is output as 1, and false would be output as 0.

Clone this wiki locally