0 day streak
c / beginner
Snippet

Logical Operators

Logical operators allow you to combine multiple conditions. && represents AND (both must be true), while || represents OR (at least one must be true).

snippet.c
c
1
2
3
4
5
6
7
8
int isAdult = 1;
int hasTicket = 0;
if (isAdult && hasTicket) {
// This won't run
}
if (isAdult || hasTicket) {
// This will run
}
Breakdown
1
isAdult && hasTicket
Checks if both variables evaluate to true (non-zero).
2
isAdult || hasTicket
Checks if at least one variable evaluates to true.