
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use of Bool in C
In C there is no predefined datatype as bool. We can create bool using enum. One enum will be created as bool, then put the false, and true as the element of the enum. The false will be at the first position, so it will hold 0, and true will be at second position, so it will get value 1. Now we can use this as datatype.
Example
#include<stdio.h> typedef enum { F, T } boolean; main() { boolean my_bool1, my_bool2; my_bool1 = F; if(my_bool1 == F) { printf("my_bool1 is false
"); } else { printf("my_bool1 is true
"); } my_bool2 = 2; if(my_bool2 == F) { printf("my_bool2 is false
"); } else { printf("my_bool2 is true
"); } }
Output
my_bool1 is false my_bool2 is true
Advertisements