c / beginner
Snippet
Logical Operators
Logical operators allow you to combine multiple boolean expressions. The '&&' (AND) operator returns true only if both conditions are met, while '||' (OR) returns true if at least one condition is met.
snippet.c
1
2
int is_valid = (age >= 18) && (has_ticket == 1);int can_enter = is_valid || is_staff;
Breakdown
1
int is_valid = (age >= 18) && (has_ticket == 1);
Checks if both age is at least 18 AND the ticket is present using the '&&' operator.
2
int can_enter = is_valid || is_staff;
Uses the '||' operator to allow entry if the user is valid OR if they are a staff member.