uniary operations in c
Answers
Answer:
An operator is a symbol that tells the compiler to perform specific mathematical or logical functions.
Every expression in the C language consist of an operand and an operator. Generally, operators require two operands to operate upon.
For example, in the expression a+b the operator ‘+’ operates upon two operands namely, 'a' and 'b'. Hence, an example of a binary operator.
Unary operators are special operators that operate upon one operand only.
In C, there are quite a few unary operators as mentioned below :-
1.)The increment and
2.) the decrement operator.
The increment operator increases the value of a variable by one. And it is of two types, the post increment and pre increment.
The pre increment operator first increases the value and then uses it for calculation whereas the post increment operator does the otherwise.
Similar explanation can be extended for the decrement operator which also has two type same as that of the increment operator.
Similarly, there are other unary operators in C such as the address-of operator denoted by the ampersand symbol ‘&’ ,which returns the address of its operand.
Suppose we have the following statement:
hours = 24;
Suppose that the address where 'hours' is stored is 0FF8. (PC addresses often are given as hexadecimal values.) Then the statement
printf("%d %p", hours, &hours);
would produce the following as output…(%p is the specifier for addresses):
24 0FF8
Ultimately,We have following Unary Operators in C.
! (logical negation),
~ (one’s complement or bitwise negation)
– (unary minus),
+ (unary plus),
& (addressof),
* (dereferencing),
++ (pre-increment),
— (pre-decrement),
sizeof operator,
(type) or cast operator
+,-,×,÷, Are uniary operators in c