Saturday, 16 August 2014

Conditional and Arithmatic Operators


CONDITIONAL operator (TERNARY operator):- the conditional operator or ternary( ?: ) is just like an if-else statement that can be written in any  expression as –  exp1 ? exp2 : exp3

 exp1 is evaluated first. If it is true then exp2 is evaluated and become the result of the expression, otherwise exp2 is evaluated and become the result of the expression.
For example :-    large=(a>b)?a:b
If int a=4,b=5,c=6,small;


Small= a<b?(a<c?a:c):(b<c?b:c)



Arithmetic operator:- 
Consider three variables:  int a=4, b=2, Result;
Operation
Operator
Syntax
Comment
Result
Multiply
*
a*b
Result=a*b
8
Divide
/
a/b
Result=a/b
2
Addition
+
a+b
Result=a+b
6
Substraction
-
a-b
Result=a-b
2
Modulus
%
A%b
Result=a%b
0





No comments:

Post a Comment