Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C99 boolean data type?

Tags:

c

types

boolean

c99

What's the C99 boolean data type and how to use it?

like image 847
eonil Avatar asked Jan 22 '11 12:01

eonil


People also ask

Does C99 have boolean?

The C99 standard for C language supports bool variables. Unlike C++, where no header file is needed to use bool, a header file “stdbool.

What data type is boolean?

In computer science, the Boolean (sometimes shortened to Bool) is a data type that has one of two possible values (usually denoted true and false) which is intended to represent the two truth values of logic and Boolean algebra.

What type is boolean in C?

C does not have boolean data types, and normally uses integers for boolean testing. Zero is used to represent false, and One is used to represent true.

What is an example of Boolean data type?

Boolean operator examples>= – True if a number is greater than or equal to another. <= – True if a number is less than or equal to another. == – True if two values are equivalent. !=


1 Answers

Include <stdbool.h> header

#include <stdbool.h>  int main(void){   bool b = false; } 

Macros true and false expand to 1 and 0 respectively.

Section 7.16 Boolean type and values < stdbool.h >

  • 1 The header <stdbool.h> defines four macros.
  • 2 The macro
    • bool expands to _Bool.
  • 3 The remaining three macros are suitable for use in #if preprocessing directives. They are
    • true : which expands to the integer constant 1,
    • false: which expands to the integer constant 0, and
    • __bool_true_false_are_defined which expands to the integer constant 1.
  • 4 Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then redefine the macros bool, true, and false.
like image 117
Prasoon Saurav Avatar answered Oct 15 '22 05:10

Prasoon Saurav