In C programming, operators are special symbols that perform specific operations on one or more operands (values or variables).
Some common types of operators in C include:
-
Arithmetic operators: perform mathematical operations such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
-
Comparison operators: compare two values and return a Boolean value indicating whether the comparison is true or false. Examples include equal to (==), not equal to (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=).
-
Logical operators: perform logical operations such as and (&&), or (||), and not (!). They are used to combine multiple comparison operators.
-
Bitwise operators: perform bit-level operations on integers. Examples include bitwise AND (&), bitwise OR (|), bitwise XOR (^), bitwise NOT (~), and bit shift operators (<<, >>).
-
Assignment operators: assign a value to a variable. The assignment operator (=) is the most basic, but there are also compound assignment operators (+=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=) which allow you to perform an operation and assign the result to a variable in a single step.
-
Ternary operator: an operator that takes three operands, it is a short-hand way of writing an if-else statement, it takes the form of: (condition)?expression1:expression2;
-
Size of operator: It returns the size of a variable or data type in bytes.
It's worth noting that C programming also has support for various other types of operators like pointer operator, member selection operator, increment/decrement operator, etc.