Operators In C & Types

 Operators In C

{tocify} $title={Table of Contents}

Definition

An Operator is a symbol, which specifies what action to be taken upon Operands. An expression is basically a combination of operands & operators that yields a single value in which operand may be a variable or constant 

Example Syntax



op1+op2

Here + is the operator and op1 and op2 are the operands

Types of operators

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. Bitwise Operators
  5. Assignment Operators
  6. Conditional Operators
  7. Special Operators
  8. Increment/Decrement Operators

  1. Arithmetic Operators


    Arithmetic operators perform arithmetic operations such as Addition, Subtraction, Multiplication, Division & Mod. Following table shows list of arithmetic operators :

    Operator Description
    + Addition
    - Substraction
    * Multiplication
    / Division
    % Modulus

    All operators except %(Modulus); can be operated on int, float & char data types, whereas % (modulus) operator can be operated on int type only.

  2. Relational Operators


    Relational operators are used to compare 1st operand with 2nd operand to test whether 1st operand is greater than/ less than or equals to 2nd operand & so on. These operators are used to form conditions, also called relational expressions and these expressions are always evaluated to either TRUE (1) or FALSE (0). Following table shows list of relational operators :

    Operator Description
    < Less than
    > Greater than
    <= Less than or equals to
    >= Greater than or equals to
    == Equals to
    != Not equals to

  3. Logical Operators


    Logical operators are also called compound relational operators , used to combine two or more conditions (relational expressions) and always evaluated to either TRUE (1) or FALSE (0). Following table shows list of Logical operators :

    Operator Description
    && Logical AND
    || Logical OR
    ! Logical NOT
  4. Bitwise Operators


    Bitwise operators perform operations on integers at bit level​. Following table shows list of Bitwise Operators :

    Operator Description
    & Bitwise AND
    | Bitwise OR
    ^ Bitwise EX-OR
    << Bitwise Left-shift
    >> Bitwise Right-shift
    ~ Bitwise NOT or Compliment

    These operators are not applicable to float & double type.

  5. Logical Operators


    Logical operators are also called compound relational operators , used to combine two or more conditions (relational expressions) and always evaluated to either TRUE (1) or FALSE (0). Following table shows list of Logical operators :

    Operator Description
    && Logical AND
    || Logical OR
    ! Logical NOT

  6. Assignment Operator


    Assignment operator is used to assign a constant value or a variable or result of an expression to a variable.

    Operator Description
    = Assignment operator

  7. Conditional Operator


    Conditional operator(?:) also know as Ternary operator because it operates upon three operands.

    Operator Description
    ?: Conditional Operator

  8. Special Operator


    The (sizeof) operator returns the size of exp or datatype in bytes.Following tables shows some examples of special operators:

    Syntax Result
    sizeof(int); returns 2
    sizeof(float); returns 4
    sizeof(char); returns 1
    sizeof(long int); returns 4

Increment/Decrement operators


The increment and decrement operators are also called as unary operators because they always operates on single operand.


Increment(++) operators

Increment (++) operator always add one to the operand

operator description
++operand Pre Increment
operand++ Post Increment

Decrement(--) operators

Decrement (--) operator always add one to the operand

operator description
--operand Pre Deccrement
operand-- Post Decrement

There is no difference between Pre/Post form of Increment/Decrement when used as individuals. But when used in expressions , the Post( Post means after) form of Increment/Decrement the value of Operand is updated after assigning the original value to the expression and in case of pre (pre means before) form of Increment/Decrement the value of operand is updated before assigning the original value to the expression.


Comments

Popular posts from this blog

Implementing Auto-Logout in PHP: Enhancing Security for Your Web App

A Simple and Professional Login Form with Gradient Background

How to Create a YouTube Subscribe Website Widget