Assignment Operators in Kotlin Hindi

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:

ExpressionEquivalent toTranslates to
a +=ba = a + ba.plusAssign(b)
a += ba = a + ba.minusAssign(b)
a *= ba = a * ba.timesAssign(b)
a /= ba = a / ba.divAssign(b)
a %= ba = a % ba.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