Operators in C are symbols that perform operations on variables and values. Operators are an essential part of programming as they enable calculations, comparisons, and logic operations. C language provides a variety of operators, which are broadly categorized into arithmetic, relational, logical, bitwise, assignment, and other types.
Arithmetic operators are used to perform mathematical operations. Common arithmetic operators include:
+
: Addition-
: Subtraction*
: Multiplication/
: Division%
: Modulus (remainder)Relational operators are used to compare two values. The result is either true (1) or false (0). Relational operators include:
==
: Equal to!=
: Not equal to>
: Greater than<
: Less than>=
: Greater than or equal to<=
: Less than or equal toLogical operators are used to combine multiple conditions. They include:
&&
: Logical AND||
: Logical OR!
: Logical NOTBitwise operators operate on individual bits of integer values. Common bitwise operators include:
&
: AND|
: OR^
: XOR~
: NOT<<
: Left shift>>
: Right shiftAssignment operators are used to assign values to variables. They include:
=
: Simple assignment+=
: Add and assign-=
: Subtract and assign*=
: Multiply and assign/=
: Divide and assign%=
: Modulus and assignAdditional operators in C include:
++
(increment) and --
(decrement)sizeof
- returns the size of a data type? :
- short form for an if-else statementOperators in C allow for a wide range of operations on variables and values. Understanding these operators is essential for performing calculations, logic, and data manipulations. Each operator category has specific purposes and enables complex functionalities within programs.