Piotrek Karpowicz
Piotrek Karpowicz

Reputation: 403

In c, in bool, true == 1 and false == 0?

Just to clarify I found similar answer but for C++, I'm kinda new to coding so I'm not sure whether it applies to C as well.

Upvotes: 37

Views: 269718

Answers (2)

Eric Lippert
Eric Lippert

Reputation: 660004

You neglected to say which version of C you are concerned about. Let's assume it's this one:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

As you can see by reading the specification, the standard definitions of true and false are 1 and 0, yes.

If your question is about a different version of C, or about non-standard definitions for true and false, then ask a more specific question.

Upvotes: 5

Neil Locketz
Neil Locketz

Reputation: 4318

More accurately anything that is not 0 is true.

So 1 is true, but so is 2, 3 ... etc.

Upvotes: 76

Related Questions