Ad space (banner)
🔧C Lessons
Lesson 18 / 68

Logical Operators (&&, ||, !)

This lesson covers C's logical operators — &&, ||, and ! — so you can combine multiple conditions in a judgment. It's for anyone searching "C logical operator usage."

Use logical operators to combine conditions. && means "both are true," || means "at least one is true," and ! negates a condition.

The example uses age >= 18 && hasTicket to check "18 or older and has a ticket," and age < 18 || !hasTicket to check "under 18, or doesn't have a ticket." Notice that, historically, C has no dedicated boolean type — 1 is treated as true.

A common early mistake is not knowing about short-circuit evaluation. Not realizing that the right side of && is skipped entirely when the left side is false can lead to unexpected behavior if the right side has a side effect.

In real projects, this is a frequently-used operator inside if statements, essential for combining conditions like "18 or older, and has a ticket" into a single check.

📖 Reference code
✍️ Your code
Type your code, then press "Run"

🧪 This site can't compile or run C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser — nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)