What Does Ternary Operator Return

The ternary operator is used to return a value based on the result of a binary condition. It takes in a binary condition as input, which makes it similar to an ‘if-else’ control flow block. It also, however, returns a value, behaving similar to a function.

What does ternary operator return in c?

This operator returns one of two values depending on the result of an expression. If “expression-1” is evaluated to Boolean true, then expression-2 is evaluated and its value is returned as a final result otherwise expression-3 is evaluated and its value is returned as a final result.

Can we write return in ternary operator?

The ternary operator has return type.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest