Logical and Comparison Operators
Explore how C evaluates conditions using operators like &&, ||, !, >, <, ==, and !=.
Logical and Comparison Operators is a free C Academy lesson on CoddyKit. This is lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, and your progress syncs across the web and the CoddyKit app. The C Academy course includes 3 lessons in total.
Logical and Comparison Operators
Logical and comparison operators help in evaluating conditions in C.
In this lesson, you will learn about:
- Comparison operators like
==,!=,>, and<. - Logical operators like
&&,||, and!.

Comparison Operators
Comparison operators are used to compare two values.
Examples:
==(Equal to)!=(Not equal to)>(Greater than)<(Less than)
Example: Comparison Operators
This program demonstrates comparison operators.
#include <stdio.h>
int main() {
int a = 5, b = 10;
printf("a == b: %d\n", a == b);
printf("a != b: %d\n", a != b);
printf("a > b: %d\n", a > b);
printf("a < b: %d\n", a < b);
return 0;
}Logical Operators
Logical operators are used to combine multiple conditions.
Examples:
&&(Logical AND)||(Logical OR)!(Logical NOT)
Example: Logical Operators
This program demonstrates logical operators.
#include <stdio.h>
int main() {
int x = 5, y = 10;
printf("(x > 0 && y > 0): %d\n", (x > 0 && y > 0));
printf("(x > 0 || y < 0): %d\n", (x > 0 || y < 0));
printf("!(x > 0): %d\n", !(x > 0));
return 0;
}Using Operators in Conditions
Comparison and logical operators are commonly used in if statements.
Example:
if (age >= 18 && age <= 65) {
printf("Eligible for work.");
}Example: Using Operators in if Statements
This program checks if a number is between 1 and 100.
#include <stdio.h>
int main() {
int num = 50;
if (num > 0 && num <= 100) {
printf("Number is in range.\n");
} else {
printf("Number is out of range.\n");
}
return 0;
}Common Mistakes
Here are common mistakes when using operators:
- Using
=instead of==in comparisons. - Forgetting parentheses in complex conditions.
- Incorrectly using logical AND (
&&) and OR (||).
Summary
In this lesson, you learned:
- Comparison operators:
==,!=,>,<. - Logical operators:
&&,||,!. - How to use these operators in conditions.
Next, we will move on to functions and modular programming in C!

Learn C with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 39
- Lessons
- 144
Frequently Asked Questions
Is the “Logical and Comparison Operators” lesson free?
Yes — the full text of “Logical and Comparison Operators” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO. The C Academy course includes 3 lessons in total.
What will I learn in “Logical and Comparison Operators”?
Explore how C evaluates conditions using operators like &&, ||, !, >, <, ==, and !=. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C Academy?
No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 3.
How long does the “Logical and Comparison Operators” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C Academy lesson?
Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Conditional Statements
- Looping Structures
- Logical and Comparison Operators