Ternary operator

C language self-study ternary operator

1 #include <stdio.h>  
 2  int main()  
 3  {  
 4      int   money= 12 ; // money in the pocket   
5      int   cost = 11.5 ; // the cost of taking a taxi   
6      printf ( " Can I take a taxi home What: " ); // The output result   
7      printf ( " %c\n " ,cost<=money ? ' y ' : ' n ' ); // *y and n need to use single quotes; ternary operation expression   
8      return  0 ;  
9      // The output result is y, that is, the operation is successful.  
10 }  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325102536&siteId=291194637