# Kotlin Operators

## Operators in Kotlin

Kotlin Operators are Arithmetic Operators, Assignment Operators, Comparison Operators, and Logical Operators.

In Kotlin language, operators are used to perform operations on given values. The operations could be mathematical, logical, etc. Based on the operation and requirement, the input values can be numeric, boolean, strings, etc.

For example, Arithmetic Addition operator takes two numeric values as operands, finds the sum of the two given numbers, and returns the result.

In this tutorial, we will go through all of the operators available in Kotlin, with examples, and references to the individual tutorials for each of the operators.

## Arithmetic Operators

The following table covers Arithmetic Operators in Kotlin.

In the following program, we take two numbers: `x`, and `y`; and perform Arithmetic Operations on these numbers.

Kotlin Program

``````fun main() {
var x = 5
var y = 2

val addValue = x + y

val subValue = x - y
println("x - y = \$subValue")

val mulValue = x * y
println("x * y = \$mulValue")

val divValue = x / y
println("x / y = \$divValue")

val modValue = x % y
println("x % y = \$modValue")

++x
println("++x = \$x")

--y
println("--y = \$y")
}``````

Output

``````x + y = 7
x - y = 3
x * y = 10
x / y = 2
x % y = 1
++x = 6
--y = 1``````

The following tutorials cover Arithmetic Operators in detail with syntax and examples.

## Assignment Operators

The following table covers Assignment Operators in Kotlin.

In the following program, we take a variable `x`, and apply different assignment operators on it with a value of `5`.

Kotlin Program

``````fun main() {
var x: Int

// Assignment
x = 21
println("x  = \$x    Assignment")

x = 21
x += 5

x = 21
// Subtraction Assignment
x -= 5
println("x  = \$x   Subtraction Assignment")

x = 21
// Multiplication Assignment
x *= 5
println("x  = \$x   Multiplication Assignment")

x = 21
// Division Assignment
x /= 5
println("x  = \$x   Division Assignment")

x = 21
// Modulus Assignment
x %= 5
println("x  = \$x   Modulus Assignment")
}``````

Output

``````x  = 21    Assignment
x  = 16   Subtraction Assignment
x  = 105   Multiplication Assignment
x  = 4   Division Assignment
x  = 1   Modulus Assignment``````

The following tutorials cover Assignment Operators in detail.

## Comparison Operators

The following table covers Comparison Operators in Kotlin.

In the following program, we take two numbers: `a`, and `b`; and perform comparison operations on these numbers.

Kotlin Program

``````fun main() {
var x = 5
var y = 2

println("x = \$x\ny = \$y")

var result: Boolean

// Equal-to
result = x == y
println("x == y   \$result")

// Not-equal
result = x != y
println("x != y   \$result")

// Greater-than
result = x > y
println("x > y    \$result")

// Less-than
result = x < y
println("x < y    \$result")

// Greater-than or Equal-to
result = x >= y
println("x >= y   \$result")

// Less-than or Equal-to
result = x <= y
println("x <= y   \$result")
}``````

Output

``````x = 5
y = 2
x == y   false
x != y   true
x > y    true
x < y    false
x >= y   true
x <= y   false``````

The following tutorials cover Comparison Operators in detail.

## Logical Operators

The following table covers Logical Operators in Kotlin.

In the following program, we take boolean values in `a`, and `b`; and perform logical operations on these values.

Kotlin Program

``````fun main() {
val x = true
val y = false
println("x && y = \${x && y}")
println("x || y = \${x || y}")
println("!x = \${!x}")
}``````

Output

``````x && y = false
x || y = true
!x = false``````

The following tutorials cover Logical Operators in detail with syntax and examples.

## More Tutorials on Operators

These are some more tutorials related to Kotlin Operators.