C Operators

C operators are symbols or characters that are used to perform specific operations on operands, such as variables or constants, in the C programming language. C operators can be classified into several categories based on the type of operations they perform. Here are some of the commonly used operators in C:

  1. Arithmetic Operators:
    • Addition: +
    • Subtraction: –
    • Multiplication: *
    • Division: /
    • Modulus (remainder): %
    • Increment: ++
    • Decrement: —
  2. Relational Operators:
    • Equal to: ==
    • Not equal to: !=
    • Greater than: >
    • Less than: <
    • Greater than or equal to: >=
    • Less than or equal to: <=
  3. Logical Operators:
    • Logical AND: &&
    • Logical OR: ||
    • Logical NOT: !
  4. Assignment Operators:
    • Assignment: =
    • Addition assignment: +=
    • Subtraction assignment: -=
    • Multiplication assignment: *=
    • Division assignment: /=
    • Modulus assignment: %=
  5. Bitwise Operators:
    • Bitwise AND: &
    • Bitwise OR: |
    • Bitwise XOR: ^
    • Bitwise NOT: ~
    • Left shift: <<
    • Right shift: >>
  6. Conditional Operator:
    • Conditional (ternary) operator: ? :
  7. Sizeof Operator:
    • Sizeof operator: sizeof

These are some of the basic operators in C. It’s important to note that operators have precedence and associativity rules that determine the order in which operations are performed when multiple operators are used in an expression. Parentheses can be used to override the default precedence and ensure the desired order of evaluation.

Precedence of Operators in C:

In C, operators have different levels of precedence, which determine the order in which they are evaluated within an expression. Here is a list of operators in C in order of decreasing precedence (operators at the top have higher precedence):

  1. Postfix operators:
    • Function call: ()
    • Array subscripting: []
  2. Unary operators:
    • Unary plus: +
    • Unary minus: –
    • Logical negation: !
    • Bitwise negation: ~
    • Prefix increment: ++
    • Prefix decrement: —
    • Dereference (indirection): *
  3. Multiplicative operators:
    • Multiplication: *
    • Division: /
    • Modulus (remainder): %
  4. Additive operators:
    • Addition: +
    • Subtraction: –
  5. Shift operators:
    • Left shift: <<
    • Right shift: >>
  6. Relational operators:
    • Less than: <
    • Less than or equal to: <=
    • Greater than: >
    • Greater than or equal to: >=
  7. Equality operators:
    • Equal to: ==
    • Not equal to: !=
  8. Bitwise AND operator: &
  9. Bitwise XOR operator: ^
  10. Bitwise OR operator: |
  11. Logical AND operator: &&
  12. Logical OR operator: ||
  13. Conditional (ternary) operator: ? :
  14. Assignment operators:
  • Simple assignment: =
  • Addition assignment: +=
  • Subtraction assignment: -=
  • Multiplication assignment: *=
  • Division assignment: /=
  • Modulus assignment: %=
  • Left shift assignment: <<=
  • Right shift assignment: >>=
  • Bitwise AND assignment: &=
  • Bitwise XOR assignment: ^=
  • Bitwise OR assignment: |=

It’s important to note that parentheses can be used to alter the precedence and enforce a specific order of evaluation. When in doubt, it’s recommended to use parentheses to make the intent of the expression clear and avoid any ambiguity.