A good answer might be:
| |
If-Else Absolute ValueIf you need an absolute value, you can do this: This is awkward for such a simple idea. The following does the same thing in one statement:if ( value < 0 ) abs = -value; else abs = value; abs = (value < 0 ) ? -value : value ; The right side of the "=" uses a conditional operator. In general, it looks like this: true-or-false-condition ? value-if-true : value-if-false
The conditional expression is a type of expression---that is, it asks for a value to be computed but does not by itself change any variable. In the above example, the variable value is not changed. | |
QUESTION 2:Given What is the value of:int a = 7, b = 21; (Remember, even though it looks funny, the entire expression stands for a single value.) Click Here after you have answered the questiona > b ? a : b |