Boolean in c | Sololearn: Learn to code for FREE!


Boolean in c

Hey, I want to create a custom header for Boolean in c language. How can I do that? I just defined true as 1 and false as 0 and I don't know what to do next. I'm new in C. I have written only LinkedList implementation and couple of excercises on c basics

6/30/2019 1:42:11 PM


5 Answers

New Answer


It already exists in the standard library. You can simply include <stdbool.h> to your program and then you'd access to predefined macros `bool`, `true`, and `false`.


I tried this and it doesn't work


I don't need use booleans yet! I just want to implement them on my own for educational purposes


I see. Let's begin with the first issue. enum cBool {true, false}; by default, the value of the first enumerator (true) start off with `0`, which means you should've begun with `false` as enum cBool {false, true}; Next is the way the enumeration instance `isTrue` has been defined. Since the enum type `cbool` hasn't typedefed, you want to make sure to proceed the definition by `enum` keyword as enum cBool isTrue = false ;


typedef int bool; #define true 1 #define false 0