Ternary operators and Return in C

前端 未结 7 1173
一向
一向 2020-12-02 23:23

Why can\'t we use return keyword inside ternary operators in C, like this:

sum > 0 ? return 1 : return 0;
相关标签:
7条回答
  • 2020-12-03 00:21

    Just by looking at the syntax you should know that an statement cannot be used in an expression. What you want can be achived by doing:return sum > 0 ? 1 : 0;

    0 讨论(0)
提交回复
热议问题