What are operators ? What is the use of operators in programming ?
While programming in any language we need to perform various operations like addition, subtraction, multiplication, division, etc.
To perform such operations in our program we requires some operators in our program which performs these operations in our program
Basically operators are used to perform some functions in our program.
There is five types of operations which is generally required throughout the program which is as follows :-
Arithmetic operators ( + , - , * , / , % , etc ) :-
The arithmetic operators in a program are used to perform some functions in a program such as addition, multiplication, division, modulus of a number, etc.
The arithmetic operations in a program always follow the basic BODMAS rule which we have studied in our schools during various calculations.
Module (%) operators in a program are used to get the remainder value in an operation.
Operators such a + + or a - - in a program are used to perform operations of increment and decrement of the values in the next line of the program.
Where as + + a and - - operators are used to perform operations such as increment and decrement of values in the same line of the program.
Bitwise operators :-
Bitwise operator in a program performs some functions in a program on bit level; it operates with the numbers 0 and 1; only no other numbers are operated in this operation.
We can understand this operation by taking one example to find AND operation in number 5 and 6 so in bitwise operation the number 5 would be written as 101 and number 6 would be written as 110 while operating these number with the and operator it will operate according to the truth table of AND operator and gives another number in bits which is 100 in this case.
We can also understand bitwise operators by the operations such as right shifts and left shifts; both these functions operate over the bit level.
Right shift ( a>> ) :- in this operation one value is displaced from right side and zero is placed at the left side on the vacant space of the number.
Let shifts ( a<< ) :- in this operation one value is displaced from the left side and zero is placed over the right side on a vacant place.
Assignment operator ( = ) :-
assignment operators are used to assign some value in any operation like we use the assignment operator to assign some value to the variable in example which is int x = 4; here the 4 is assigned in the variable x as its value.
Comparison operator :-
This operator is used to compare two operands in a program we can understand the comparison operator with one example which is
int a = 3 ;
int b = 7 ;
system.out.println ( a>b ) ;
the output of the above example will be false as the number 3 is not greater then the number 7
We can use various other operations such as ‘==’, ‘!=’, etc. operator in our programs to compare the values as it is equal or not we can understand this peraton by taking an another example which is
int a = 3 ;
int b = 3 ;
system .out. println ( a==b )
and the output of the above program will be true because the values of a and b are equal which is 3 that's why it will return the output as true
Also the operator always returns a boolean value as an output which is either true or false.
logical operator :-
logical operators used to perform various logical operations on the program such as AND (&) operator, OR (||) operator, NOT (!) operator which we have seen above in bitwise operator
i hope the above mentioned information helps you to understand about the operator of program and also helps the beginner programmer to learn about the operators from basics
thankyou
BY :- ADARSH GUPTA


No comments:
Post a Comment