Operators in C

An expression consists of variables and constants separated by Operators in C. There are 7 types of Operators in C as listed below:

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Increment and decrement operators
  • Assignment Operators
  • Conditional Operators
  • Bitwise Operators

    1. Arithmetic Operators : Arithmetic Operators are used to perform arithmetic operations.

    OperatorMeaningExampleResult
    +addition4+26
    -subtraction4-22
    *multiplication4*28
    /division4/22
    %modulus4%20

    2. Relational Operators : Relational Operators are used to compare the values of operands or expressions to produce a logical value. A logical is either true or false.

    OperatorMeaningExampleResult
    <less than4<3false
    >greater than4>3true
    <=less than or equal to4<=3false
    >=greater than or equal to4>=3true
    (==)equal to4==3false
    !=not equal to4!=3true

    3. Logical Operators : Logical Operators are used to connect more relational operations to form a complex expression that is called Logical Operators or Logical expression. A value obtained by evaluating a logical expression is always logical either true or false.

    OperatorMeaningExampleResult
    &&logical and(4<3)&&(4>3)false
    ||logical or(4<2) || (4>3)true
    !logical not! (4<2)true

    4. Increment and Decrement operators (++ and – –) : Increment operator (++) is used to increase the value of an integer or char variable by 1. Decrement operator (- -) is used to reduce the value of an integer or char variable by 1. Consider the following examples :

    a = 25;
    a++ or ++a will produce the result a = 26
    a = 25;
    a- – or – -a will produce the result a = 24

    5. Assignment Operators : Assignment Operators are used to perform arithmetic operations while assigning a value to a variable.

    6. Conditional Operators or Ternary Operators (?:) : Conditional Operators is used to check a condition and select a value depending on the value of the condition. Normally the selected value will be assigned to a variable which has the following form :

    variable=(condition)?value1:value2;
    

    Example :

    big=(x>y)?x:y;
    

    7. Bitwise Operators : Bitwise Operators are used to perform operations at a binary digit level. These operators are not commonly used and used only in special applications where optimized use of storage is required.

    OperatorMeaning
    <<Shifts the bits to left
    >>Shifts the bit to right
    ~Bitwise inversion
    &Bitwise logical and
    |Bitwise logical or
    ^Bitwise exclusive or

    Recommended Posts:

    C
        1. Fundamental of C Language
        2. Keywords in C
        3. Data Types in C
        4. Operators in C
        5. Type Conversion in C
        6. Input/Output Functions in C
        7. C Program to Swap Two Numbers With or Without Temporary Variables
        8. Control Statements in C – if, else, switch
        9. Loop Control Statements in C | for, while, do-while loop
        10. Comparison Between for loop while loop and do-while loop
        11. Unconditional Control Transfer Statements in C
        12. C Program to Check Armstrong Number
        13. C Program to Generate Fibonacci Series
        14. C Program to Check Whether a Number is Prime or Not
        15. C Program to Convert Binary Number to Decimal
        16. C Program to Convert Decimal Number to Binary
        17. Arrays in C – One-Dimensional, Two-Dimensional Array
        18. C Program to Find the Largest Number in an Array
        19. C Program to Sort an Array in Ascending Order
        20. C Program to Add Two Matrices
        21. C Program to Multiply Two Matrices
        22. C Program to Find Transpose of a Matrix
        23. String Manipulations In C
        24. C program to count number of vowels in a string
        25. C Program to Check whether the Given String is a Palindrome
        26. C Program to Concatenate Two Strings without using strcat()
        27. C Program to Convert Lowercase to Uppercase
        28. Functions in C
        29. C Program to Find Factorial of a Number using Function
        30. C Program to Reverse a Number using Function
        31. C Program to Reverse a String using Function
        32. Recursion in C
        33. C Program to Find Factorial of a Number Using Recursion
        34. C Program to Print Fibonacci Series using Recursion
        35. Local and Global Variables in C
        36. Storage Classes in C
        37. Pointers in C
        38. Call by Value in C using Pointers
        39. Call by Reference in C using Pointers
        40. Difference between Call by Value and Call by Reference
        41. C Program to Add Two Numbers using Pointers
        42. C Program to Find Largest of Two Numbers using Pointers
        43. Dynamic Memory Allocation in C | malloc(), calloc(), free() and realloc()
        44. C Program to count Vowels in a string using Pointer
        45. C program to Check if a string is palindrome using Pointers
        46. C Program to Copy String Using Pointers
        47. Structure and Union in C
        48. Difference between Structure & Union
        49. File handling in C
        50. C Program to Create a File and write in it
        51. C program to copy contents of one file to another