Use of bool in C

Prerequisite: Bool Data Type in C++

The C99 standard for C language supports bool variables. Unlike C++, where no header file is needed to use bool, a header file “stdbool.h” must be included to use bool in C. If we save the below program as .c, it will not compile, but if we save it as .cpp, it will work fine.

filter_none

edit
close

play_arrow

link
brightness_4
code

int main()
{
  bool arr[2] = {true, false};
  return 0;
}

chevron_right


If we include the header file “stdbool.h” in the above program, it will work fine as a C program.

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdbool.h>
int main()
{
  bool arr[2] = {true, false};
  return 0;
}

chevron_right


Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


9


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.