Types of unary operators in C++

Unary operators in C++

Types of unary operators in C++



Unary operators in C++ are those operators which have single operand. They are of following types:

1. Unary Plus operator in C++ (+)

This operator specifies that a number is positive. It is optional to put this operator before a number as a number without sign is considered positive automatically.

Example: +14, 45

 2. Unary Minus operator in C++ (-)

This operator makes a number negative.

Example:  -1, -455

 3. Pointer operator in C++ (*)

This operator can be used to declare a pointer variable .

Example

int *p;

**Above Example declares a pointer variable p .

 4. Address operator in C++ (&)

This operators basically refer to location of a variable in memory.

Example:

int n=20,*p;
p=&n

**Above example assigns  the address of variable n into pointer variable p.

5. Increment operator in C++ (++)

6. Decrement operator in C++ (–)



Spread the love
Lesson tags: address operator in C++, decrement in C++, increment in C++, pointer operators in C++, unary minus in C++, unary plus in C++
Back to: C++ Programming Notes
Spread the love