C programming language provides a wide range of operators that are used to perform various operations on variables and values. Here are the most common types of operators used in C:
- Arithmetic Operators:
- Addition (+): Adds two operands.
- Subtraction (-): Subtracts the second operand from the first operand.
- Multiplication (*): Multiplies two operands.
- Division (/): Divides the first operand by the second operand.
- Modulus (%): Returns the remainder of the division operation.
- Increment (++) and Decrement (–): Increase or decrease the value of an operand by 1.
- Relational Operators:
- Equal to (==): Checks if the values of two operands are equal.
- Not equal to (!=): Checks if the values of two operands are not equal.
- Greater than (>): Checks if the value of the left operand is greater than the value of the right operand.
- Less than (<): Checks if the value of the left operand is less than the value of the right operand.
- Greater than or equal to (>=): Checks if the value of the left operand is greater than or equal to the value of the right operand.
- Less than or equal to (<=): Checks if the value of the left operand is less than or equal to the value of the right operand.
- Logical Operators:
- Logical AND (&&): Returns true if both the operands are true.
- Logical OR (||): Returns true if either of the operands is true.
- Logical NOT (!): Reverses the logical state of its operand.
- Assignment Operators:
- Simple Assignment (=): Assigns the value on the right to the variable on the left.
- Compound Assignment Operators (+=, -=, *=, /=, %=): Performs the operation and assigns the result to the variable.
- Bitwise Operators:
- Bitwise AND (&): Performs a bitwise AND operation between two operands.
- Bitwise OR (|): Performs a bitwise OR operation between two operands.
- Bitwise XOR (^): Performs a bitwise exclusive OR operation between two operands.
- Bitwise NOT (~): Flips the bits of the operand.
- Left Shift (<<): Shifts the bits of the left operand to the left by the number of positions specified by the right operand.
- Right Shift (>>): Shifts the bits of the left operand to the right by the number of positions specified by the right operand.
- Conditional (Ternary) Operator:
- Conditional Operator (?:): Evaluates a condition and returns one of two possible expressions based on the condition.
- sizeof Operator: Returns the size (in bytes) of a data type or variable.
- Address and Indirection Operators:
- Address (&): Returns the memory address of a variable.
- Indirection (Pointer Dereference) (*): Accesses the value stored in the memory address pointed to by a pointer variable.