Soumyadeep Dey
PRO
2 months ago
Soumyadeepcountry asked

In C, when I assign a comparison like result = total > 100, why does the output end up being either 0 or 1?

Kelish Rai
Expert
last month
Kelish Rai answered

In C, when you use a comparison like total > 100, it doesn’t return true or false as words — it returns a number:

  • 1 if the condition is true

  • 0 if it’s false

So if you write:

result = total > 100;

C checks if total is greater than 100. If it is, result becomes 1. If not, result becomes 0.

That’s why the output is either 0 or 1 — it's just how C handles boolean logic under the hood.

If you have more questions, I am here to help.

C
This question was asked as part of the Learn C Programming course.