🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

C Operators — Arithmetic, Relational, Logical, Assignment

C FundamentalsC Operators🟢 Free Lesson

C Operators — Arithmetic, Relational, Logical, Assignment

Learning Objectives

  • Apply arithmetic operators to compute values
  • Compare values with relational operators
  • Combine conditions with logical operators
  • Use assignment operators and understand precedence

What Is an Operator?

An operator is a symbol that tells the compiler to perform a calculation or comparison. Operators work on values called operands. The result of an operation is either a new value or, in the case of assignment, an updated variable. C groups operators into several families that you will use constantly.

Arithmetic Operators

Arithmetic operators perform basic math. Most behave as you would expect from a calculator, with a few important differences to remember.

OperatorNameExampleResult
plusAddition7 plus 310
minusSubtraction7 minus 34
starMultiplication7 times 321
slashDivision7 divided by 32 integer
percentModulus7 mod 31 remainder
int a = 17;
int b = 5;

printf("%d\n", a + b);
printf("%d\n", a - b);
printf("%d\n", a * b);
printf("%d\n", a / b);
printf("%d\n", a % b);

Integer division truncates toward zero, so 17 divided by 5 gives 3, not 3.4. The modulus operator returns the remainder after division and is extremely useful for cycling values or checking even and odd numbers.

Division by zero is undefined behavior in C. Always guard divisors before performing a division that could receive a zero.

Relational Operators

Relational operators compare two operands and produce an integer result of one when the condition is true and zero when it is false. You will use them inside conditionals constantly.

OperatorMeaning
double equalsEqual to
exclamation equalsNot equal to
greater thanLarger value
less thanSmaller value
greater equalsGreater or equal
less equalsLess or equal
int x = 10;
int y = 20;

printf("%d\n", x == y);
printf("%d\n", x != y);
printf("%d\n", x < y);

A classic beginner error is writing a single equals sign when you meant to compare. A single equals assigns a value, while double equals tests equality. Using assignment inside a condition often causes hard-to-spot bugs.

Logical Operators

Logical operators combine or invert conditions. C treats any non-zero value as true and zero as false. Short-circuit evaluation means the right side may be skipped entirely when the result is already decided.

int age = 25;
int hasTicket = 1;

if (age >= 18 && hasTicket == 1) {
    printf("You may enter.\n");
}

if (age < 13 || age > 65) {
    printf("Discount applies.\n");
}

if (!(age == 0)) {
    printf("Age is not zero.\n");
}

The AND operator requires both sides to be true. The OR operator needs at least one true side. The NOT operator flips a condition. Together they let you express complex rules clearly.

Assignment Operators

Assignment stores a value in a variable. C also provides compound assignment operators that combine a calculation and a store into one step, keeping code compact and readable.

int score = 100;
score += 5;
score -= 10;
score *= 2;
score /= 4;
score %= 7;

Each compound form is shorthand for the longer expression. The plus-equals form adds then assigns, and the pattern continues for the other operators. Increment and decrement operators, written as two plus signs or two minus signs, add or subtract one from a variable.

Operator Precedence

When operators appear together, precedence decides which runs first. Multiplication and division bind tighter than addition and subtraction. Comparisons run after arithmetic, and logical AND binds tighter than logical OR. Parentheses override the default order and make intent obvious.

int result = 2 + 3 * 4;
printf("%d\n", result);

int clearer = (2 + 3) * 4;
printf("%d\n", clearer);

The first expression prints 14 because multiplication happens first. The second prints 20 because parentheses force addition first. When precedence feels unclear, add parentheses rather than guessing.

📝Precedence Tip

Read complex expressions from the inside out. If you cannot explain the evaluation order quickly, rewrite the line with explicit parentheses or split it into intermediate variables.

Key Takeaways

💡

  • Arithmetic operators include addition, subtraction, multiplication, division, and modulus
  • Integer division truncates and division by zero is undefined
  • Relational operators return one for true and zero for false
  • Logical AND, OR, and NOT combine conditions with short-circuit behavior
  • Parentheses beat memorizing precedence tables for readable code

Practice Questions

  1. What is the result of 17 divided by 5 using integer division, and what does 17 mod 5 return?
  2. Why is using a single equals sign inside an if condition dangerous?
  3. How do compound assignment operators such as plus-equals improve readability?

Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type — Always start by categorizing the problem
  2. Incorrect formula application — Verify the formula applies to your specific case
  3. Unit errors — Always check units are consistent throughout
  4. Sign errors — Pay careful attention to positive and negative values
  5. Rounding too early — Keep full precision until the final answer
  6. Forgetting constraints — Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-11-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert C Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement