Kotlin OperatorOperators are special characters which perform operation on operands (values or variable).There are various kind of operators available in Kotlin.
Arithmetic OperatorArithmetic operators are used to perform basic mathematical operations such as addition (+), subtraction (-), multiplication (*), division (/) etc.
Example of Arithmetic OperatorOutput: 15 5 50 2 0 Relation OperatorRelation operator shows the relation and compares between operands. Following are the different relational operators:
Example of Relation Operator Output: b is greater than a. max = 10 Assignment operatorAssignment operator "=" is used to assign a value to another variable. The assignment of value takes from right to left.
Example of Assignment operator Output: a+=b :25 a-=b :20 a*=b :100 a/=b :20 a%=b :0 Unary OperatorUnary operator is used with only single operand. Following are some unary operator given below.
Example of Unary Operator Output: +a :10 -b :-5 ++a :11 --b :4 !flag :false Logical OperatorLogical operators are used to check conditions between operands. List of logical operators are given below.
Example of Logical Operator Output: (a>b) && (a>c) :false (a>b) || (a>c) :true !flag :true Bitwise OperationIn Kotlin, there is not any special bitwise operator. Bitwise operation is done using named function.
Example of Bitwise Operation Output: a.shl(b): 40 a.shr(b): 2 a.ushr(b:) 2 a.and(b): 2 a.or(b): 10 a.xor(b): 8 a.inv(): -11 Next TopicKotlin Input/Output |