There is an error. Is it wrong to assign a value to a[i] in the following code? Or something is wrong with conditional operators?
#include
#in
This is really a matter of understanding the syntax of the conditional operator. This is spelled out in §6.5.15 of the C11 Standard:
conditional-expression:
logical-OR-expression
logical-OR-expression ? expression : conditional-expression
Thus, the third operand to the conditional operator must be a conditional-expression. Tracing the possibilities for conditional expressions through the grammar defined in the Standard, one finds that an assignment expression is not one of the options. The relevant syntax definitions are found in §6.5 Expressions.
By following the chain of possibilities from conditional-expression all the way back to primary-expression, it can be seen that a conditional-expression may be a logical-OR-expression, or a logical-AND-expression, or an inclusive-OR-expression, or an exclusive-OR-expression, or an AND-expression, or an equality-expression, or a relational-expression, or a shift-expression, or an additive-expression, or a multiplicative expression, or a cast-expression, or a unary-expression, or a postfix-expression, or a primary-expression. A primary-expression is an identifier, a constant, a string-literal, an ( expression ), or a generic-selection.
So, an assignment-expression (which may be a conditional expression) is not on the list of possibilities for a conditional expression. This is the reason for the error reported in the question: since an assignment expression is not valid syntax here, the statement:
a[i]>90 ? a[i]=a[i]-32 : a[i]=a[i]+32;
is interpreted as:
(a[i]>90 ? a[i]=a[i]-32 : a[i]) = a[i]+32;
The left side of the above assignment expression is not a modifiable lvalue, as required for an assignment expression, hence the error.
But, note that a parenthesized expression of the form ( expression ) is a valid conditional-expression, and an assignment-expression is an expression. So, this is a legal statement:
a[i]>90 ? a[i]=a[i]-32 : (a[i]=a[i]+32);
All of that said, this is probably not the right way to code this. Better to use one of the alternatives proposed in other answers, such as:
a[i] += a[i] > 90 ? -32 : 32;