Assignment Operators in Kotlin Hindi

Assignment operators are used to assign value to a variable. We have already used simple assignment operator = before.

val age = 5

Here, 5 is assigned to variable age using = operator.

Here's a list of all assignment operators and their corresponding functions:

Expression Equivalent to Translates to
a +=b a = a + b a.plusAssign(b)
a += b a = a + b a.minusAssign(b)
a *= b a = a * b a.timesAssign(b)
a /= b a = a / b a.divAssign(b)
a %= b a = a % b a.modAssign(b)

Example: Assignment Operators

fun main(args: Array<String>) {
    var number = 12

    number *= 5   // number = number*5
    println("number  = $number")
}

When you run the program, the output will be:

number = 60