0Pricing
C Academy · Lesson

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 — 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, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

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 !.
Logical and Comparison Operators — illustration 1

2

Comparison Operators

Comparison operators are used to compare two values.

Examples:

  • == (Equal to)
  • != (Not equal to)
  • > (Greater than)
  • < (Less than)

3

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;
}

4

Logical Operators

Logical operators are used to combine multiple conditions.

Examples:

  • && (Logical AND)
  • || (Logical OR)
  • ! (Logical NOT)

5

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;
}

6

Using Operators in Conditions

Comparison and logical operators are commonly used in if statements.

Example:

if (age >= 18 && age <= 65) { printf("Eligible for work."); }

7

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;
}

8

9

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 (||).

10

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!

Logical and Comparison Operators — illustration 10

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, and the C Academy course includes 3 lessons in total. 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.

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; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.

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

  1. Conditional Statements
  2. Looping Structures
  3. Logical and Comparison Operators
← Back to C Academy