In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the use of the ternary operator in C language? I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Generally speaking, the ternary operator in C language is a?b:c, that is, there are three quantities involved in the operation.
The general form of a conditional expression consisting of conditional operators is: expression 1? Expression 2: expression 3 evaluates as follows: if the value of expression 1 is true, the value of expression 2 is taken as the value of the conditional expression, otherwise the value of expression 2 is taken as the value of the entire conditional expression. Conditional expressions are usually used in assignment statements. For example, conditional statements:
If (a > b) max=a;else max=b; can be written as max= (a > b)? a max using conditional expressions; the semantics of executing this statement are: if a > b is true, assign a to max, otherwise assign b to it. When we use conditional expressions, we should also pay attention to the following points: (1) the operation priority of conditional operators is lower than that of relational operators and arithmetic operators, but higher than that of assignment operators. So max= (a > b)? a b?a:b b can remove the parentheses and write as the conditional operator max=a > ARV (2)? And: are a pair of operators and cannot be used separately. (3) the binding direction of conditional operators is from right to left. For example: a > b?a:c > d?c:d should be understood as a > bounded a: (c > d?c:d) this is the case where conditional expressions are nested, where expression 3 is another conditional expression. Void main () {int aforamagram printf ("\ n input two numbers:"); scanf ("% d% d", & aPowerprintb); printf ("max=%d", a > b?a:b); / / for "what is the ternary operator", it can be understood as if () statement one; else statement two; a? B: c}
After reading the above, have you mastered the method of ternary operator in C language? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.