JaVa
   

Unary, Binary, and Ternary Operators

Quite simply, a unary operator is one that is used with one operand. For example, in the operator precedence table we see the second row contains the + and – unary operators, which may, for the unary minus operator, be used as follows:

int a = 10;
int b = -a;


Hence, the minus sign preceding the variable a in the second line is a unary operator, used with one operator—the variable a. Binary operators are used to perform an operation on two operands, such as the * operator for multiplying two numbers together.

There is only one ternary operator, which is the ?: conditional operator that uses three operands and is discussed a little later in this chapter.

JaVa
   
Comments