Labels

Monday, April 11, 2022

Operators in Scala (Class -30)

 An Operator is a symbol that represents an operation that is to be performed in the program. 

      Operators tell the compiler to perform a specific operation; each operator is associated with one and has a unique identification code. Operators play an important role in programming and they are used to make an expression that executes to perform a task. 

Scala as a huge range of operators:

a)      a)   Arithmetic operators

b)     Relational operators

c)      Logical operators

d)     Bitwise operators

e)      Assignment operators


a)      Arithmetic operators: to perform Arithmetic operations such as +, -, *, /, %, etc.

b)      A Relational operator is used to define the comparison between the two operators. It is also known as a comparison operator.

              E.g.:- Equal to (==), Not Equal to (!=), Greater than (>), Less than (<), etc.

c) A Logical operator is used to combine the logical output (true / false) or reverse to the logical output of a condition or operand.

          E.g.:- And (&&), OR (II), Not (!), etc.

d) Bitwise operators works on the bits of the operands. It operates on every bit of the operands to give output.

        E.g.:- XOR (^), Right Shift (>>), Complement (~), etc.

e) The Assignment operator (=) is used to assign value to a variable. The variable is at the left of the operator and value is at the right of the operator. The data type needs to be the same for both sides to avoid errors in the program.

         E.g.:- (+=), (-=), (*=), (%=), (&=), etc.

No comments:

Post a Comment