Operators In Programming Explained

Operators in programming languages are symbols that can perform many operations on the data variable or attribute and methods or functions.In programming language like java the operators play a very important key role in programming languages to do various operations easily. Based on the type of operations the operators are classified into many groups.

Operators are classified as:

  • Arithmetic Operators
  • Assignment Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary Operators
  • Increment and Decrement Operators
Why need operators?
 Operators are the backbone of any programming language. From a simple additional program to complex algorithms requires an operator to do any operations In a real-time project you will be working on handling n number of data. 


Operands and Operators:
 In a programming language, every operation is done with the help of an operator and operand. For example, consider an addition operation a =a+b.  Here the variables "a" and "b" are operands and "+" is an arithmetic symbol to tell the program to do an addition operation using a and b. Then the value is stored in "a" using an assignment operator "=". This is how the operand and operators are useful in a programming language.

1. Arithmetic Operators: This operators are used to perform arithmetic operations on primitive data types.
Sytanx: < Operand><Operator><Operand>
Example: a+b. Here a and b are operands and "+" is an arithmetic operator
  • Addition(+):  Adds two values and provides an output
  • Subtraction(-): Subtract one value from another value
  • Multiplication(*): Multiply two values
  • Division(/): Divides one value from another and return quotient as output
  • Modulo(%): Divides one value from another and return reminder as output

2. Assignment Operators: This operators are used to assign value from one variable to another variable. 
  • Assignment Operator(=):  Assign a value to a variable 
  • Compound Operators(+=, -=,*=, /=, %=):  It's a combination of  arithmetic operations and multiplication operation. The arithmetic operator should be at left and the assigment operator should be next to arithmetic operator. First arithmetic operator will be performed then the value assigned to the varilable. For example, Consider a operation a+=b, this line of code do the same operation of a=a+b. a+=b is another form of a=a+b. This example will perform a+b using "+" and assign the value back to a using "=".  Compound Operators related operations can be performed only when the operand should be on the left side to get the value and also in the right side to perform some operation 

3. Logical Operators: This operators are used to do logical AND and logical OR operations in programming. This  programming AND and OR  operations are very similar to AND gate and OR gate operations in electronic. Programming language like java has one more operator that is Logical NOT and it returns inverse of boolean value. If Logical NOT applied boolean "true" then false will be returned. Logical Operators are extensively used if and else condition
  • Logical AND(&&): 0&&1=>return 0
  • Logical OR(||): 0||1 => returns 1
  • Logical NOT(!): !true -> return false

4. Relational Operators: This operators are used to perform relation operations such as greater than , lesser  than and equal to..etc between two operands. Relational operators always return boolean value after performing relation operation. This operators are extensively used in loops, if and else condition. 
  • Equal to(==):  Checks two operands are equal or not . Example, a==b, checks a is equal to b and return true if it's equal 
  • Not Equal to(!=): Checks two operands are equal or not. Example, a!=b , checks a is not equal to b and return true if it's not equal
  • Greater than(>): Checks the left operand is greater than right operand. Example, checks a>b, a is greater than b and return true if "a" is greater
  • Greater than or Equal to(>=): Checks the left operand is greater than or eqaul to right operand. Example, checks a>=b, checks a is either greater than b or equal to b and return true if "a" is greater than or equals
  • Less than(<): Checks the left operand is less than right operand. Example, checks a<b, a is less than b and return true if "a" is less
  • Greater than or Equal to(>=): Checks the left operand is less than or eqaul to right operand. Example, checks a>=b, checks a is either less than b or equal to b and return true if "a"  is less than or equals

5. Increment and Decrement Operators: This operator are used to increase or decrease by number 1. This operators are really useful in iterators or loops in programming
  • ++(increment): a++, increase value by +1
  • --(decrement):  a--, decrease value  by -1
Note:  The operators ++ or -- can be post (a++) or prefix(++a)


6. Bitwise Operators: This operators perform bitwise operation and manipulate the individual bits.
  • Bitwise AND(&)
  • Bitwise OR(||)
  • Bitwise XOR(^)
  • Bitwise NOT(~)
  • Left shift (<<)
  • Right shift (>>)

7. Tenary Operators: This operator is an simple form of if else condition. It has three part condition,true value and false value.
 Syntax: condition ? if true : if false

Post a Comment

Previous Post Next Post
B