Unary Operators in Kotlin Hindi
Here's a table of unary operators, their meaning, and corresponding functions:
Operator | Meaning | Expression | Translates to |
---|---|---|---|
+ | Unary plus | +a | a.unaryPlus() |
- | Unary minus (inverts sign) | -a | a.unaryMinus() |
! | not (inverts value) | !a | a.not() |
++ | Increment: increases value by1 | ++a | a.inc() |
-- | Decrement: decreases value by 1 | --a | a.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")
--c
println("--c = $c")
}
When you run the program, the output will be:
-a = -1
!b = false
--c = 0