Bool vs _Bool - C Data Type

C examples for Data Type:bool

Introduction

You can use bool as the type name when adding stdbool.h to your source file.

stdbool.h defines the symbols true and false to correspond to 1 and 0, respectively.

A nonzero numeric value will result in 1 (true) when cast to type bool, and 0 will cast to 0 (false).

If you include the header in your source file, you can write the declaration as the following:

Demo Code

#include <stdio.h> 
#include <stdbool.h> 
int main(void) { 

  bool valid = true;         // Boolean variable initialized to true
  printf("%d",valid);
  return 0; //from  w  w w  .j  a  v a  2 s .c  om
}

Result


Related Tutorials