Unary  Operators in Kotlin Hindi

Unary  Operators in Kotlin Hindi

Here's a table of unary operators, their meaning, and corresponding functions:

OperatorMeaningExpressionTranslates to
+Unary plus+aa.unaryPlus()
-Unary minus (inverts sign)-aa.unaryMinus()
!not (inverts value)!aa.not()
++Increment: increases value by1++aa.inc()
--Decrement: decreases value by 1--aa.dec()

Example: Unary Operators

fun main(args: Array<String>) {
    val a = 1
    val b = true
    var c = 1

    var result: Int
    var booleanResult: Boolean

    result = -a
    println("-a = $result")

    booleanResult = !b
    println("!b = $booleanResult")

    println("--c = $c")

When you run the program, the output will be:

-a = -1
!b = false
--c = 0