Operators in C

  • C Arithmetic Operators: An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division etc on numerical values (constants and variables).

                            Operator Meaning of Operator

                                    + addition or unary plus

                                    - subtraction or unary minus

                                    * multiplication

                                    / division

                                    % remainder after division (modulo division)

  • Increment ++ operator and decrement -- operator to change the value of an operand (constant or variable) by 1.

                            Operator      Meaning of Operator

                                ++ increment

                                -- decrement

  • C Assignment Operators: An assignment operator is used for assigning a value to a variable. The most common assignment operator is =

                            Operator Example Same as

                                = y = z         y = z

                                += y += z y = y+z

                                -= y -= z y = y-z

                                *= y *= z y = y*z

                                /= y /= z y = y/z

                                %= y %= z y = y%z

  • C Relational(conditional) Operators: A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0. Relational operators are used in decision making and loops.

                            Operator Meaning of Operator Example

                                    == Equal to 14 == 12 is evaluated to 0

                                    > Greater than 14 > 12 is evaluated to 1

                                    < Less than         14 < 12 is evaluated to 0

                                   != Not equal to 14 != 12 is evaluated to 1

                                   >= Greater than or equal to 14 >= 12 is evaluated to 1

                                   <= Less than or equal to 14 <= 12 is evaluated to 0

  • C Logical Operators: An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C programming.

                            Operator Meaning Example

                                   && Logical AND. True only if all operands are true If a = 6 and b = 2 then,                                                                                                         expression ((a==6) && (b>4)) equals to 0.

                                       || Logical OR. True only if either one operand is true If a = 6 and b = 2 then,                                                                                                     expression ((a==6) || (b>4)) equals to 1.

                                       ! Logical NOT. True only if the operand is 0 If a = 6 then,
                                                                                             expression !(a==6) equals to 0.

  • C Bitwise Operators: During computation, mathematical operations like: addition, subtraction, multiplication, division, etc are converted to bit-level which makes processing faster and saves power. Bitwise operators are used in C programming to perform bit-level operations.

                                Operators Meaning of operators

                                        & Bitwise AND

                                        | Bitwise OR

                                        ^ Bitwise exclusive OR

                                        ~ Bitwise complement

                                        << Shift left

                                        >> Shift right

  • Comma Operator: Comma operators are used to link related expressions together. 

For example: variable declaration :- int x, y = 5, z;

  • sizeof operator: The sizeof is a unary operator that returns the size of data (constants, variables, array, structure, etc).
  • ternary operator ?:
  • reference operator &, 
  • dereference operator * 
  • member selection operator ->