Arithmetic Operators:
Arithmetic operators perform basic mathematical calculations on numbers. These operators are fundamental in calculations and data manipulation.
+ (Addition) adds two values.
– (Subtraction) subtracts one value from another.
* (Multiplication) multiplies two numbers.
/ (Division) divides one number by another.
% (Modulus) returns the remainder of division.
Relational Operators:
Relational operators compare two values and return a Boolean (true or false). They help in decision-making and conditional checks. The main operators are:
== (Equal to) checks if values are equal.
!= (Not equal to) checks if values are different.
< (Less than) checks if the left value is smaller.
> (Greater than) checks if the left value is larger.
<= (Less than or equal to)
>= (Greater than or equal to) also exist.
Logical Operators:
Logical operators are used to combine multiple conditions or invert them, primarily in control flow statements. They help build complex conditional logic.
&& (Logical AND) returns true if both conditions are true.
|| (Logical OR) returns true if at least one condition is true.
! (Logical NOT) inverts the Boolean value.
Bitwise Operators:
Bitwise operators work at the binary level, manipulating individual bits of numbers. They are useful in low-level programming and performance-critical tasks.
& (AND), | (OR), ^ (XOR) combine bits.
~ (NOT) inverts bits.
<< (Left shift) and >> (Right shift) move bits left or right.
Assignment Operators:
Assignment operators assign or update values in variables. The basic one is “=”. Compound operators perform an operation and assign simultaneously.
= assigns a value.
+= adds and assigns.
-= subtracts and assigns.
*= multiplies and assigns.
/= divides and assigns.