C Programming Operators
C has a variety of operators that are used to perform various operations in a program. These operators can be broadly classified into six categories: arithmetic operators, assignment operators, comparison operators, logical operators, bitwise operators, and others.
Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations such as addition, subtraction, multiplication, division, and others. The following table lists the arithmetic operators in C and their descriptions along with examples:
Name | Description | Example |
---|---|---|
+ | Addition | x + y |
- | Subtraction | x - y |
* | Multiplication | x * y |
/ | Division | x / y |
% | Modulus | x % y |
Assignment Operators
Assignment operators are used to assign values to variables. The following table lists the assignment operators in C and their descriptions along with examples:
Name | Description | Example |
---|---|---|
= | Assignment | x = y |
+= | Addition Assignment | x += y |
-= | Subtraction Assignment | x -= y |
*= | Multiplication Assignment | x *= y |
/= | Division Assignment | x /= y |
%= | Modulus Assignment | x %= y |
Comparison Operators
Comparison operators are used to compare values and return a Boolean value indicating the result of the comparison. The following table lists the comparison operators in C and their descriptions along with examples:
Name | Description | Example |
---|---|---|
== | Equal To | x == y |
!= | Not Equal To | x != y |
> | Greater Than | x > y |
< | Less Than | x < y |
>= | Greater Than or Equal To | x >= y |
<= | Less Than or Equal To | x <= y |
Logical Operators
Logical operators are used to perform logical operations such as AND, OR, and NOT. The following table lists the logical operators in C and their descriptions along with examples:
Name | Description | Example |
---|---|---|
&& | Logical AND | x && y |
|| | Logical OR | x || y |
! | Logical NOT | !x |
Bitwise Operators
Bitwise operators are used to perform operations on individual bits of a binary number. The following table lists the bitwise operators in C and their descriptions along with examples:
Name | Description | Example |
---|---|---|
& | Bitwise AND | x & y |
| | Bitwise OR | x | y |
^ | Bitwise XOR | x ^ y |
~ | Bitwise NOT | ~x |
<< | Left Shift | x << y |
>> | Right Shift | x >> y |