1
|
In mathematics, a unary operation is an operation with only one operand, i.e. an operation with a single input, or in other words, a function of one variable (for the terminology see also operators versus functions).
Common notations are prefix notation (+, −, not), postfix notation (factorial: n!), and functional notation (sin x or sin (x)). In the case of the square root a horizontal bar over the argument extending the square root sign can indicate the extent of the argument, so that parentheses can be dispensed with.
Contents |
Unary operators (called "monadic" in APL) are also used in programming languages. For example, in the C family of languages, the following operators are unary:
In most programming languages, incremental and decremental operators can be preffixed and suffixed to the variable. The preffix and suffix can be useful when manipulating variables. A suffixed operation increments the value after it has been called.
int i = 0;
printf (" %i \n %i ", i++ , i++ );
Output:
0
1
Whereas a prefixed operation will increment the value before it has been called.
int i = 0;
printf (" %i \n %i ", ++i, ++i);
Output
1
2
The usage of incremental and decremental operators is usually found in For loops
This article is licensed under the GNU Free Documentation License. It uses material from Wikipedia