If C doesnā€™t have Boolean values, what is the alternative in situations that would normally require one? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 9

If C doesnā€™t have Boolean values, what is the alternative in situations that would normally require one?

15th Oct 2018, 3:43 PM
Drew Pesall
Drew Pesall - avatar
6 Respostas
+ 15
StandardĀ CĀ (since C99) provides aĀ boolean type, called _Bool . By including the header stdbool.h , one can use the more intuitive nameĀ boolĀ and the constants true and false . ... Objective-CĀ alsoĀ hasĀ a separateĀ Boolean data type BOOLĀ , with possible values being YES or NO , equivalents of true and false respectively. Initial implementations of the languageĀ C(1972) provided no Boolean type, and to this day Boolean values are commonly represented by integers ( int s) inĀ CĀ programs. The comparison operators ( > , == , etc.) are defined to return a signed integer ( int ) result, eitherĀ 0Ā (forĀ false) or 1 (forĀ true).
15th Oct 2018, 3:51 PM
Abhivarshini Maddala
Abhivarshini Maddala - avatar
+ 7
On one project, I've worked it was: #define TRUE 1 #define FALSE 0
16th Oct 2018, 7:14 AM
shaldem
shaldem - avatar
+ 5
bool works! as said by Abhi Varshini https://code.sololearn.com/cS7jNLt09tRk/?ref=app Isn't it bool? I mean cool šŸ˜‚
17th Oct 2018, 5:24 AM
Infinity
Infinity - avatar
+ 2
Though C doesnā€™t support Boolean value. But we can use Logical Operators like ā€˜&&ā€™, ā€˜||ā€™ or ā€˜!ā€™. We can do several logical program with these. If any one need some Fuzzy Logic boolean values, it can be modified by define preprocessors shaldem mention before..
16th Oct 2018, 6:17 PM
Bits!
- 1
Use 0 and 1
2nd May 2019, 6:30 PM
Werg Serium
Werg Serium - avatar
- 1
0 is false and 1 is true
2nd May 2019, 6:31 PM
Werg Serium
Werg Serium - avatar