Professional Documents
Culture Documents
Used to determine logic between variable/values. Only conditional operator that takes 3 operands.
Its and replacement for if-then-else
Symbol--> ? :
Egs:-
num1 = 10;
num2 = 20;
res=(num1>num2) ? (num1+num2):(num1-num2)
Since num1<num2,
the second operation is performed
res = num1-num2 = -10
Certain operators have higher precedence than others and therefore precedence of operator decides how an expression
should be evaluated.
ICSE 2015
b + c ->
Here b and c are the operands and + is the operator.
Noticed how the operator was put at different locations but all means the same.
PRE ORDER
++a
Implicit
byte -> short -> char -> int -> long -> float -> double
Explicit
double -> float -> long -> int -> char -> short -> byte
Egs:-
double a=45.5;
int b=(int)a; --> 45
double a=45;
int a='A';