if (condition)
do x;
else
do y;
looks like (condition) ? do x : do y;
when written using a
conditional expression, lower
reads as follows:
/* lower: convert c to lower case; ASCII only */
int lower(int c)
{
if (c >= 'A' && c <= 'Z')
return c + 'a' - 'A';
else
return c;
return (c >= 'A' && c <= 'Z') ? c + 'a' - 'A' : c;
}
The syntax may seem cryptic, especially if this is your first time seeing it, so try using conditional expressions in previous exercises where possible in order to become more comfortable with them.