Operators in C Programming (Arithmetic, Relational, Logical, Assignment)
This tutorial explains operators in C programming, which are used to perform operations on variables and values. It covers arithmetic, relational, logical, and assignment operators with syntax and examples, helping beginners understand how expressions and conditions work in C programs.
1. What Are Operators in C
Operators are symbols that perform operations on operands (variables or values).
Example:
Here, + is an operator.
2. Arithmetic Operators
Arithmetic operators are used to perform mathematical calculations.
Operators List
| OperatorDescription | |
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus (remainder) |
Example Program
3. Relational Operators
Relational operators are used to compare two values and return true (1) or false (0).
Operators List
| OperatorMeaning | |
== | Equal to |
!= | Not equal |
> | Greater than |
< | Less than |
>= | Greater than or equal |
<= | Less than or equal |
Example
4. Logical Operators
Logical operators are used to combine multiple conditions.
Operators List
| OperatorMeaning | |
&& | Logical AND |
| ` | |
! | Logical NOT |
Example
5. Assignment Operators
Assignment operators are used to assign values to variables.
Operators List
| OperatorDescription | |
= | Assign |
+= | Add and assign |
-= | Subtract and assign |
*= | Multiply and assign |
/= | Divide and assign |
%= | Modulus and assign |
Example
6. Operator Precedence (Basic)
Operators with higher precedence are evaluated first.
Example:
Key Points to Remember
- Arithmetic operators perform calculations
- Relational operators compare values
- Logical operators combine conditions
- Assignment operators update variable values
- Understand precedence to avoid logical errors