What are C Operators Explained Simply- C Programming Course Online

Need Help or More Information?

Questions about this free C programming course, embedded C training or career guidance? Get in touch.

Free C Programming Course • Chapter 4 • Lecture 1

C Operators Explained Simply

Operators, operands and expressions, plus the arithmetic operators every embedded C programmer uses daily. Part of our free C programming course on EmbeddedPathashala.

10
Operator families
2
Unary arithmetic operators
5
Binary arithmetic operators

Welcome to Chapter 4 of our free C programming course. Until now you have stored data in variables. Operators are how you actually do something with that data: add it, compare it, combine it, change it. If you are looking for a free C tutorial that explains operators from the ground up, with programs you can compile on your own laptop, you are in the right place.

This lecture introduces the vocabulary (operator, operand, expression) and then covers the arithmetic operators. Later lectures in this free C programming course cover integer arithmetic, floating-point arithmetic, assignment, increment and decrement, relational, logical and bitwise operators.

What You Will Learn in This Free C Tutorial

  • What an operator, an operand and an expression are
  • The ten families of operators in C
  • The difference between unary and binary operators
  • All five binary arithmetic operators: + - * / %
  • Why the modulus operator % rejects floating-point operands
  • Why C has no exponent operator and what to use instead (pow())
  • How unary minus differs from binary subtraction

Prerequisites

You should know what a variable is, the basic data types (int, float, double), and how to compile a C file with gcc. If not, revisit the earlier chapters of this free C programming course first.

Operator, Operand and Expression

An operator is a symbol that tells the compiler to perform one specific operation and produce a value. An operand is the piece of data the operator works on. An operand can be a variable, a constant, or even another expression. When operands and operators are joined together in a legal way, the result is an expression, and every expression evaluates to a value.

Take the line total = price * qty. Here price and qty are operands of the multiplication operator, and the multiplication result becomes the right-hand operand of the assignment operator. One line, two operators, one expression tree.

Anatomy of an expression: total = price * qty
total (operand) = (operator) price (operand) * (operator) qty (operand)
Step 1: price * qty gives a value Step 2: that value is stored in total

Unary and Binary Operators

Operators are classified by how many operands they need. A unary operator works on exactly one operand (-y). A binary operator needs two (x + y). C also has one ternary operator (?:) that takes three, which you will meet in the conditional operator lecture.

The Ten Operator Families in C

C packs a large number of operators, grouped into families. This free C programming course covers all of them across Chapter 4 and Chapter 5.

#FamilyTypical symbolsUsed for
1Arithmetic+ – * / %Numeric calculation
2Assignment= += -= *= /= %=Storing values in variables
3Increment / decrement++ —Adding or subtracting 1
4Relational< > <= >= == !=Comparing two values
5Logical&& || !Combining conditions
6Conditional?:Inline if/else value
7Comma,Sequencing expressions
8sizeofsizeofSize of a type or object in bytes
9Bitwise& | ^ ~ << >>Working on individual bits (vital in embedded)
10Other[] () . -> & *Arrays, calls, structure access, pointers

Arithmetic Operators in C

Arithmetic operators perform numeric calculations. They come in two flavours: unary arithmetic operators and binary arithmetic operators.

Unary Arithmetic Operators

There are two: unary plus (+x) and unary minus (-y). Unary minus flips the sign of its operand. Unary plus returns the value unchanged; it exists mostly for symmetry and readability.

Do not confuse them with + and -: the same symbols act as unary operators when they have one operand, and as binary addition or subtraction when they sit between two operands. In 5 - -3 the first minus is binary and the second is unary, so the result is 8.

Binary Arithmetic Operators

OperatorMeaningExampleResult
+Addition9 + 413
–Subtraction9 – 45
*Multiplication9 * 436
/Division9 / 42 (both are int)
%Remainder of integer division9 % 41
Which operand types each arithmetic operator accepts
+ – * / int and int: OK float/double: OK mixed: OK
% int and int: OK float/double: COMPILE ERROR mixed with float: COMPILE ERROR

Modulus and the Missing Exponent Operator

The modulus operator % works only on integer operands. Applying it to a float or double is rejected by the compiler. If you need a floating-point remainder, the standard library provides fmod() in <math.h>.

C also has no exponent operator. The caret ^ is bitwise XOR, not power. To raise a number to a power, call pow() from <math.h>, which takes and returns double. On Linux, link the math library with -lm.

Hands-On Examples (Free C Programming Course Labs)

Save each program in its own file and compile with gcc -Wall -Wextra -std=c11 file.c -o out. Add -lm where math.h functions are used.

Example 1: Unary Plus and Minus

/* cp4_1_ex1.c - unary operators */
#include <stdio.h>

int main(void)
{
    int temp = 25;
    int flipped = -temp;
    int same = +temp;

    printf("temp=%d flipped=%d same=%d\n", temp, flipped, same);
    printf("-(-temp) = %d\n", -(-temp));
    return 0;
}

Expected output:

temp=25 flipped=-25 same=25
-(-temp) = 25

Notice that temp itself never changes. Unary minus produces a new value; it does not modify the variable.

Example 2: All Five Binary Operators

/* cp4_1_ex2.c - binary arithmetic */
#include <stdio.h>

int main(void)
{
    int a = 29, b = 6;

    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);
    printf("a %% b = %d\n", a % b);
    return 0;
}
a + b = 35
a - b = 23
a * b = 174
a / b = 4
a % b = 5

To print a literal percent sign with printf you must write %%. Check the relationship: 4 × 6 + 5 = 29.

Example 3: Power with pow()

/* cp4_1_ex3.c - exponentiation */
#include <stdio.h>
#include <math.h>

int main(void)
{
    double result = pow(2.0, 10.0);
    printf("2 to the power 10 = %.0f\n", result);
    return 0;
}
$ gcc cp4_1_ex3.c -o ex3 -lm
$ ./ex3
2 to the power 10 = 1024

Example 4: The Compiler Rejects % on Floats

/* cp4_1_ex4.c - this one does NOT compile */
#include <stdio.h>

int main(void)
{
    double x = 7.5;
    printf("%f\n", x % 2);
    return 0;
}
$ gcc cp4_1_ex4.c -o ex4
cp4_1_ex4.c: In function 'main':
cp4_1_ex4.c:6:24: error: invalid operands to binary % (have 'double' and 'int')

Reading compiler errors is a core skill. The message names the operator and the exact operand types it refused.

Real-World Uses of Arithmetic Operators

  • Embedded firmware: converting sensor counts to physical units, computing timer reload values, scaling PWM duty cycles.
  • Linux system programs: computing buffer sizes, offsets and page counts.
  • Everyday software: billing totals, tax, discounts, unit conversions.

Common Mistakes and Troubleshooting

MistakeWhat happensFix
Using ^ for powerSilently computes bitwise XORUse pow() or multiply manually
Using % on floatCompile errorUse fmod()
Forgetting -lmLinker error: undefined reference to powAdd -lm after the source file
Writing % alone in printfGarbage or warningWrite %%
Dividing by zeroUndefined behaviour or a crashCheck the divisor first

Best Practices

  • Use parentheses to make intent obvious, even where precedence would give the same answer.
  • Prefer int main(void) and always compile with -Wall -Wextra.
  • Never let a divisor reach zero; validate input before dividing.
  • Keep one operation per line while learning, so you can print and inspect intermediate values.
  • Performance note: on most embedded cores multiplication is cheap but division and modulus can be slow, especially on small microcontrollers with no hardware divider.

Key Takeaways

  • An expression is operands joined by operators, and it always yields a value.
  • Unary operators take one operand, binary take two.
  • Arithmetic operators: + - * / %, plus unary + and -.
  • % works only on integers; C has no exponent operator, use pow().

Conclusion

Operators are the verbs of the C language. You now know the vocabulary, the ten operator families, and the arithmetic operators with their restrictions. The next lecture of this free C programming course digs into integer arithmetic, where division and modulus behave in ways that surprise most beginners.

Quick Quiz

  1. How many operands does the unary minus operator need?
    Show answerOne.
  2. What is the value of 14 % 5?
    Show answer4.
  3. Which header declares pow()?
    Show answermath.h.
  4. Is 7.0 % 2 valid in C?
    Show answerNo. The compiler gives an invalid operands error.
  5. What does 8 - -2 evaluate to?
    Show answer10.

Interview Questions

  1. Define operator, operand and expression with an example.
  2. What is the difference between unary minus and binary subtraction?
  3. Why can’t you use % with floating-point numbers, and what is the alternative?
  4. Does 2 ^ 3 give 8 in C? Explain.
  5. Why is division considered expensive on small microcontrollers?

Frequently Asked Questions

Is this free C programming course suitable for absolute beginners?

Yes. Every lecture starts from basics, uses small programs, and shows exact commands and expected output.

What is an operator in C?

A symbol that performs a specific operation on one or more operands and produces a value.

How many arithmetic operators does C have?

Five binary operators (+ - * / %) and two unary operators (+ and -).

Is there a power operator in C?

No. Use pow() from math.h and link with -lm.

Why does % fail with float?

The remainder operation is defined only for integer types in C. Use fmod() for floating-point values.

Is this free C tutorial useful for embedded systems?

Yes. The examples and notes highlight how operators behave on microcontrollers and in Linux programs.

Keep Going with the Free C Programming Course

Next up: integer arithmetic, truncating division and the modulus operator in depth.

Need Help or More Information?

Questions about this free C programming course, embedded C training or career guidance? Get in touch.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *