Is there any operator in c that is both unary and binary?

Is there any operator in c that is both unary and binary? This question was asked in an interview.

+4
source share
3 answers

An asterisk (*) can be used for dereference (unary) or multiplication (binary).

Ampersand (&) can be used to bind (unary) or bitwise AND (binary).

The plus / minus signs (+/-) can be used to identify / negate (unary) or add / subtract (binary).

But, as others have pointed out, these are characters shared by different operators. Each of these operators has only one n-arity.

+9
source

, . , , .

:

  • *
  • -
  • +
  • & ""

* - , , , .

+5

, . , C ( ):

.: - Unary: - {.meber1 = x, .member3 = z} (C99 ). : .


C , .
, +, -, * &, , :

  • +, - Unary: i = -1 j = +1. : i = i+1, j = j+1
  • *Unary: dereference operator. Binary: multiplication operator.
  • &Unary operator: Reference. Binary: bitwise operator AND.
+2
source

Source: https://habr.com/ru/post/1543142/


All Articles