Unary expressions
An operator that accepts a single operand is called a unary operator, and expressions built using unary operator are called unary expressions.Increment and decrement operators also fall under this category.
Unary plus:
It is represented by a singleplus (+
) symbol. It multiplies a single operand by +1
. In the following example, we assign a variablep
with value -5
.On applying the unary plus operator to the variable, it multiplies the variable p
with +1
and again stores the result inside p
, as follows:
$ awk 'BEGIN{ p = -5; p = +p; print "p = ",p }'
The output on execution of the preceding code is as follows:
p = -5
Unary minus:
It is represented by a single minus(-
) symbol. It multiplies a single operand by -1
. In the following example, we assign a variablep
with value -5
.On applying the unaryminusoperator, it multiplies the variable p
by -1
and again stores the result inside p
:
$ awk 'BEGIN{ p = -5; p = -p; print "p = ",p }'
The output on execution of the preceding code is as...