### Kotlin Operator

Operators are symbols that perform mathematical or logical operations. It used to perform operations on values and variables.

Types of Operators in Kotlin

•  Arithmetic operator
• Relation operator
• Assignment operator
• Unary operator
• Logical operator
• Bitwise operator

1. Arithmetic Operators – This operators are used to perform mathematical operations.

``````fun main()
{
var x = 10
var y = 3
println(x + y) //13
println(x .plus(y))//13
println(x - y)//7
println(x.minus(y))//7
println(x * y) //30
println(x.times(y))//30
println(x / y)//3
println(x.div(y))//3
println(x % y)//1
println(x.rem(y))////1
}
``````

2. Relational Operators These operators are used to compare two values and return Boolean value(true or false).

compareTo returns zero if this object is equal to the specified other object and returns negative number if it’s less than other, or returns a positive number if it’s greater than other.

``````fun main()
{
var x = 10
var y = 37
var z = 37
println(x.compareTo(y))//-1
println(y.compareTo(z))//0
println(y.compareTo(x))//1
}
``````

``````fun main()
{
var x = 10
var y = 37
println(x > y) //false
println(x.compareTo(y)>0)//false
println(x < y)//true
println(x.compareTo(y)<0)//true
println(x >= y) //false
println(x.compareTo(y) >= 0)//false
println(x.compareTo(y) <= 0)//true
println(x == y)//false
println( x?.equals(y))//false
println(x != y)//true
println(!(x.equals(y)))//true
}
``````

3. Assignment Operators – it’s used to assign values to variable

``````fun main()
{
var a = 10
var b = 37
a+=b
println(a) // 47
a-=b
println(a) //10
a*=b
println(a)// 370
a/=b
println(a) // 10
a%=b
println(a)//10
}
``````

4. Unary Operators – It uses with only single operand

pre increment operator : ex ++a -It increments the value of variable before using it

Post-increment operator : ex a++ – It increments the value of the variable after executing the expression

``````fun main()
{
var a = 10
val flag = false
println(-a)// -10
println(a) // 10
println(+a) // 10
println(a.unaryMinus()) // -10
println(a.unaryPlus()) // 10
println(++a)//11
println(a++) // 11 // this is post incriement first incriment then  assignn
println(a) // 12
println(--a)// 11
println(a) // 11
println(a--)// 11
println(a) // 10
println(!flag) // true
}
``````

5. Logical Operator : This is used to check condition between operands

``````fun main(args : Array<String>){
var a = 50
var b = 20
var c = 5
var flag = false
println((a>b) && (a>c)) // true
println((c>b) || (a>c)) // true
println(!flag)
}
``````