bool v/s int flag

i have to develop a program where i have to check for a condition and assign a variable a value true or false so i am confused between these two approach.
1 bool test = true
then according to case make it false or true,
2 int flag = 1
and then change it to 0 or 1;

which approach is better and why
There are some differences to them.

Example:

with an int: 1 != -1;

with a bool: bool(1) == bool(-1);

And for me a bool is clearer to use in true or false cases cause it simply says what it is.
The bool flag "false" is equal to 0. The bool flag "true" will return "1" when typed and anything that is not zero is equivalent to true if I am making sense.

You could easily use int, I see it done all of the time, however I prefer to use bool because it is a little clearer with what the label is used for.
Using bool helps other programmers understand your code (or even yourself a lot of time later).
When they see int they don't immediately know if you actually store a number or just use it as a flag.

Also: only 0 means false, anything other than 0 means true.
Last edited on
Topic archived. No new replies allowed.