Operators are the foundation of any programming language. Thus the functionality of C language is incomplete without the use of operators. Operators allow us to perform different kinds of operations on operands. In C, operators in Can be categorized in following categories:
- Arithmetic Operators (+, -, *, /, %, post-increment, pre-increment, post-decrement, pre-decrement)
- Relational Operators (==, !=, >, <, >= & <=) Logical Operators (&&, || and !)
- Bitwise Operators (&, |, ^, ~, >> and <<)
- Assignment Operators (=, +=, -=, *=, etc)
- Other Operators (conditional, comma, sizeof, address, redirection)
Arithmetic Operators: These are used to perform arithmetic/mathematical operations on operands. The binary operators falling in this category are:
- Addition: The ‘+’ operator adds two operands. For example, x+y.
- Subtraction: The ‘-‘ operator subtracts two operands. For example, x-y.
- Multiplication: The ‘*’ operator multiplies two operands. For example, x*y.
- Division: The ‘/’ operator divides the first operand by the second. For example, x/y.
- Modulus: The ‘%’ operator returns the remainder when first operand is divided by the second. For example, x%y.
a is 10 and b is: 4 a+b is: 14 a-b is: 6 a*b is: 40 a/b is: 2 a%b is: 2
The ones falling into the category of unary arithmetic operators are:
- Increment: The ‘++’ operator is used to increment the value of an integer. When placed before the variable name (also called pre-increment operator), its value is incremented instantly. For example, ++x.
And when it is placed after the variable name (also called post-increment operator), its value is preserved temporarily until the execution of this statement and it gets updated before the execution of the next statement. For example, x++.
- Decrement: The ‘ – – ‘ operator is used to decrement the value of an integer. When placed before the variable name (also called pre-decrement operator), its value is decremented instantly. For example, – – x.
And when it is placed after the variable name (also called post-decrement operator), its value is preserved temporarily until the execution of this statement and it gets updated before the execution of the next statement. For example, x – –.
a is 11 and res is 10 a is 10 and res is 11 a is 11 and res is 11 a is 10 and res is 10
We will soon be discussing other categories of operators in different posts.
To know about Operator Precedence and Associativity, refer this link:
This article is contributed by Ayush Jaggi. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to sum two integers without using arithmetic operators in C/C++?
- Operators in C | Set 2 (Relational and Logical Operators)
- Set a variable without using Arithmetic, Relational or Conditional Operator
- Ratio Manipulations in C++ | Set 1 (Arithmetic)
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Multidimensional Pointer Arithmetic in C/C++
- Character arithmetic in C and C++
- Sum of array using pointer arithmetic
- Output of C programs | Set 55 (Ternary Operators)
- Output of C programs | Set 55 (Shift Operators)
- Output of C programs | Set 58 (operators)
- What are the operators that can be and cannot be overloaded in C++?
- Increment (Decrement) operators require L-value Expression
- Order of operands for logical operators
- Advanced C++ | Conversion Operators
- const_cast in C++ | Type Casting operators
- Bitwise Operators in C/C++
- Execution of printf with ++ operators
- What are the differences between bitwise and logical AND operators in C/C++?
- C | Operators | Question 2