Unary operators in C++

Unary operator: is operations that function to produce a new value on a single operand.

a) unary minus: A minus operator modifies the argument’s symbol. A positive number becomes negative, so it becomes a positive negative number.

Unary minus is dissimilar from decrement operator since two operands are required for subtraction.

b) Increment: It’s being used to raise the variable value by 1. The raise can be done in two different ways

prefix increment

The operator precedes the operand by this method (+ + a). Until it is was using the operand value would be altered.

postfix increment

The operator follows the operand in this procedure (a + +). After it has been were using the value operand will be changed.

c) decrement

It’s being used to decrease the variable value by 1. The rise can be affected in 2 directions

prefix decrement

The operator precedes the substring in this technique (– -a). Until it has been was using, the operand value would be altered.

posfix decrement

The operator tends to follow the iterator in that method ( a–). Once it’s been included, the operand value is modified.

C++ program for Prefix and Postfix combination operations:

Output:

Unary operators in C++

d) NOT(!): This is used to change its operand ‘s logical condition. If a statement is fulfilled, therefore the operator Logical NOT will make it not true.

e) Addressof operator(&): This provides a variable url. It serves to revert back a variable’s memory location. Such addresses returned by the operator’s address are recognized as reference points because they “point” in memory to the factor.

f) sizeof(): That operator produces its operand length, in bytes. The operator’s length every time invokes its operand. An expression is an operand, or it may be a cast.

Output:

Unary operators in C++

Pin It on Pinterest

Share This