C Programming

Use of bool

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.

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

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

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

Recent Comments

Feedback

For any feedback,email us at feedback@geeksforgeeks.org

Report a Bug

For any report or bug,email us at support@geeksforgeeks.org