Need Help or More Information?
Questions about this free C programming course, embedded C training or career guidance? Get in touch.
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.
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.
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.
| # | Family | Typical symbols | Used for |
|---|---|---|---|
| 1 | Arithmetic | + – * / % | Numeric calculation |
| 2 | Assignment | = += -= *= /= %= | Storing values in variables |
| 3 | Increment / decrement | ++ — | Adding or subtracting 1 |
| 4 | Relational | < > <= >= == != | Comparing two values |
| 5 | Logical | && || ! | Combining conditions |
| 6 | Conditional | ?: | Inline if/else value |
| 7 | Comma | , | Sequencing expressions |
| 8 | sizeof | sizeof | Size of a type or object in bytes |
| 9 | Bitwise | & | ^ ~ << >> | Working on individual bits (vital in embedded) |
| 10 | Other | [] () . -> & * | 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.
5 - -3 the first minus is binary and the second is unary, so the result is 8.Binary Arithmetic Operators
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | Addition | 9 + 4 | 13 |
| – | Subtraction | 9 – 4 | 5 |
| * | Multiplication | 9 * 4 | 36 |
| / | Division | 9 / 4 | 2 (both are int) |
| % | Remainder of integer division | 9 % 4 | 1 |
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
| Mistake | What happens | Fix |
|---|---|---|
Using ^ for power | Silently computes bitwise XOR | Use pow() or multiply manually |
Using % on float | Compile error | Use fmod() |
Forgetting -lm | Linker error: undefined reference to pow | Add -lm after the source file |
Writing % alone in printf | Garbage or warning | Write %% |
| Dividing by zero | Undefined behaviour or a crash | Check 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, usepow().
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
- How many operands does the unary minus operator need?
Show answer
One. - What is the value of
14 % 5?Show answer
4. - Which header declares
pow()?Show answer
math.h. - Is
7.0 % 2valid in C?Show answer
No. The compiler gives an invalid operands error. - What does
8 - -2evaluate to?Show answer
10.
Interview Questions
- Define operator, operand and expression with an example.
- What is the difference between unary minus and binary subtraction?
- Why can’t you use
%with floating-point numbers, and what is the alternative? - Does
2 ^ 3give 8 in C? Explain. - 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