C Programming
Master the fundamentals of C programming with comprehensive tutorials, examples, and hands-on exercises
Operators in C
Operators are symbols that perform operations on variables and values. C provides a rich set of operators for different types of operations.
Arithmetic Operators
Used to perform mathematical operations:
| Operator | Description | Example | Result |
|---|---|---|---|
+ |
Addition | 5 + 3 |
8 |
- |
Subtraction | 5 - 3 |
2 |
* |
Multiplication | 5 * 3 |
15 |
/ |
Division | 15 / 3 |
5 |
% |
Modulus (remainder) | 7 % 3 |
1 |
Assignment Operators
= Simple Assignment
x = 5; assigns 5 to x
+= Add and Assign
x += 3; same as x = x + 3;
-= Subtract and Assign
x -= 2; same as x = x - 2;
*= Multiply and Assign
x *= 4; same as x = x * 4;
Comparison Operators
Used to compare two values and return true (1) or false (0):
== Equal to!= Not equal to> Greater than< Less than>= Greater than or equal<= Less than or equal
Operators Example
#include <stdio.h>
int main() {
int a = 10, b = 3;
// Arithmetic operators
printf("Arithmetic Operations:\n");
printf("%d + %d = %d\n", a, b, a + b);
printf("%d - %d = %d\n", a, b, a - b);
printf("%d * %d = %d\n", a, b, a * b);
printf("%d / %d = %d\n", a, b, a / b);
printf("%d %% %d = %d\n", a, b, a % b);
// Assignment operators
int x = 5;
printf("\nAssignment Operations:\n");
printf("x = %d\n", x);
x += 3;
printf("After x += 3: %d\n", x);
x *= 2;
printf("After x *= 2: %d\n", x);
// Comparison operators
printf("\nComparison Operations:\n");
printf("%d == %d: %d\n", a, b, a == b);
printf("%d > %d: %d\n", a, b, a > b);
printf("%d < %d: %d\n", a, b, a < b);
return 0;
}
Explanation
- Arithmetic:
+,-,*,/,%perform math on numeric types. - Assignment: Compound operators like
+=,*=update variables succinctly. - Comparison: Return 1 (true) or 0 (false) and are commonly used in conditions.
- Common pitfalls: Integer division truncates results; operator precedence can surprise—use parentheses to be explicit.
Keywords
C operators, arithmetic, assignment, comparison, precedence, integer division
Quick Tips
- Use parentheses to control evaluation order and improve readability.
- Be mindful of integer division; cast to
doublefor precise results. - Prefer clear, simple expressions over clever but confusing ones.
Frequently Asked Questions
C is a powerful, general-purpose programming language that's been around since the 1970s. It's the foundation for many modern languages and is essential for system programming, embedded systems, and understanding how computers work at a low level. Learning C gives you a solid foundation in programming fundamentals.
No prior programming experience is required! Our C programming tutorial is designed for complete beginners. We start with the basics and gradually progress to more advanced topics. However, having some basic computer literacy and logical thinking skills will be helpful.
You need a C compiler to run C programs. For beginners, we recommend using our online C compiler which requires no installation. For local development, you can use GCC (GNU Compiler Collection) which is available on Windows (via MinGW), macOS (via Xcode), and Linux. IDEs like Code::Blocks, Dev-C++, or Visual Studio Code are also helpful.
The time to learn C depends on your dedication and prior experience. With consistent practice (1-2 hours daily), you can grasp the basics in 2-4 weeks and become proficient in 2-3 months. Mastering advanced concepts like pointers, memory management, and data structures may take 6-12 months of regular practice.
C programming skills open doors to various career paths including system programming, embedded systems development, operating system development, device driver programming, game development, and firmware development. Many companies in automotive, aerospace, telecommunications, and IoT sectors actively seek C programmers.
Absolutely! C remains highly relevant and is consistently ranked among the top programming languages. It's essential for system programming, embedded systems, IoT devices, and performance-critical applications. Many modern languages are built on C, and understanding C helps you become a better programmer overall.