Wednesday, January 15, 2025
HomeProgrammingWhat is the use of Bool type in C Programming

What is the use of Bool type in C Programming

In C, the bool type is used to represent Boolean values, which can be either true or false. Although C originally didn’t have a native Boolean type, it was introduced with the C99 standard.

Usage:
To use bool, you need to include the <stdbool.h> header file:
c
#include <stdbool.h>

See also  Java Collections class

Key Points:
– bool is an alias for _Bool, which is a built-in data type in C99.
– The values true and false are macros defined as 1 and 0, respectively.

Example:
c
#include <stdio.h>
#include <stdbool.h>

int main() {
bool isHappy = true;
if (isHappy) {
printf(“I am happy!\n”);
} else {
printf(“I am not happy.\n”);
}
return 0;
}

See also  How to Print in Java

Output:

I am happy!

The bool type makes code more readable and explicitly conveys the intent of Boolean operations

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x