Is there any operator in c which is both unary and binary ? This question was asked in one of the interview.
The asterisk (*) can be used for dereferencing (unary) or multiplication (binary).
The ampersand (&) can be used for referencing (unary) or bitwise AND (binary).
The plus/minus signs (+/-) can be used for identity/negation (unary) or addition/subtraction (binary).
But, as others pointed out, those are symbols shared by different operators. Each of those operators have only one n-arity.
No, there isn't. Every operator is either unary, binary, or ternary.
Some unary and binary operators happen to use the same symbol:
*
for dereference and multiplication-
for negation and subtraction+
for identity and addition&
for address-of and bitwise "and"But unary and binary *
are still distinct operators that happen to be spelled the same way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With