[Beginner, C] If we can represent true/false with 1/0, why do we need the stdbool library and boolean variables?

https://programming.dev/post/47210489

[Beginner, C] If we can represent true/false with 1/0, why do we need the stdbool library and boolean variables? - programming.dev

I saw one example int x = 10; int y = 5; bool isGreater = x > y; printf("%d", isGreater); But I could write this int x = 10; int y = 5; printf("%d", x > y); I am a compete beginner and I have no real reason why I would or would not want to deal boolean variables, but I want to understand their raison d’être.

Sometimes you need to store a value that is either true or false and refer to it later or maybe update it. Maybe you have some complicated logic for when a loop needs to end that you can’t really represent in the while condition. You can make the while check your bool variable and then set it to false when you are ready to end. Perhaps you have a function that returns a bool value and you setup your logic so there is a default return value but you do some calculations and sometimes you want to return the other value. it lets you have a single return statement in the function which can be easier to read.

You use boolean variables in the same way as other variables. The example you share is indeed contrived. In that situation you need no variables at all. That example is merely showing the syntax.

Thank you for the explanation! Perhaps at my novice level, I should just go with it and learn the use of bool as I experience it. :)