Write a conditional statement using ternary operator if X has a value greater than 20 then increment the value of J by 1 otherwise decrement the value of J by 2.
Answers
Answered by
0
Answer:
In C++, the statement is as follows
(X>20) ? (J++) : (J-2) ;
Explanation:
In C++, the conditional operator is kind of similar to the if-else statement as it does follow the same algorithm as of if-else statement but the conditional operator takes less space and helps to write the if-else statements in the shortest way possible.
The syntax for a conditional operator is as follows ;
variable = Expression1 ? Expression2 : Expression3
Hence, the correct solution is (X>20) ? (J++) : (J-2) ;
Similar questions