Operators In C

 Table of Contents 

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. Assignment Operators
  5. Bitwise Operators
  6. Conditional
  7. Sizeof Operator
  8. Comma Operator

    Operators in C | Embedded Wala

    Operators in the C programming language are symbols or special characters designed to perform various operations on operands, including variables, constants, or expressions. They play a fundamental role in programming languages by enabling data manipulation and computational tasks. C offers a diverse set of operators, categorized based on their functionality, to cater to different programming needs.

    1. Arithmetic Operators :

    • Addition (+) : Adds two values together.
    • Subtraction (-) : Subtracts the second value from the first.
    • Multiplication (*) : Multiplies two values.
    • Division (/) : Divides the first value by the second.
    • Modulo (%) : Returns the remainder of the division operation.
    • Increment (++) : Increases the value of a variable by 1.
    • Decrement (--) : Decreases the value of a variable by 1.

    2. Relational Operators :

    • Equal to (==) : Checks if two values are equal.
    • Not equal to (!=) : Checks if two values are not equal.
    • Greater than (>) : Checks if the first value is greater than the second.
    • Less than (<) : Checks if the first value is less than the second.
    • Greater than or equal to (>=) : Checks if the first value is greater than or equal to the second.
    • Less than or equal to (<=) : Checks if the first value is less than or equal to the second.

    3. Logical Operators :

    • Logical AND (&&) : Returns true if both conditions are true.
    • Logical OR (||) : Returns true if at least one condition is true.
    • Logical NOT (!) : Reverses the logical state of a condition.

    4. Assignment Operators :

    • Assignment (=) : Assigns a value to a variable.
    • Addition assignment (+=) : Adds a value to the variable and assigns the result.
    • Subtraction assignment (-=) : Subtracts a value from the variable and assigns the result.
    • Multiplication assignment (*=) : Multiplies the variable by a value and assigns the result.
    • Division assignment (/=) : Divides the variable by a value and assigns the result.
    • Modulo assignment (%=) : Computes the modulo of the variable with a value and assigns the result.

    5. Bitwise Operators :

    • Bitwise AND (&) : Performs a bitwise AND operation between two values.
    • Bitwise OR (|) : Performs a bitwise OR operation between two values.
    • Bitwise XOR (^) : Performs a bitwise exclusive OR operation between two values.
    • Bitwise NOT (~) : Inverts the bits of a value.
    • Left shift (<<) : Shifts the bits of a value to the left by a specified number of positions.
    • Right shift (>>) : Shifts the bits of a value to the right by a specified number of positions.

    6. Conditional (Ternary) Operator :

    • Conditional expression ? true expression : false expression : Evaluates a condition and returns one of two possible values based on the result of the condition.

    7. Sizeof Operator :

    • Sizeof : Returns the size, in bytes, of an object or a data type.

    8. Comma Operator :

    • Comma-separated expressions (,) : Evaluates multiple expressions sequentially and returns the value of the last expression.