Lesson 18 - ternary operator and comma expression

· Ternary operator (a b:? C) of the logical operation as a carrier for

· Rule: When a true value, the return value of b; otherwise, return the value of c.

 

On ternary operator

#include <stdio.h>



int main ()

{

    int a = 1;

    int b = 2;

    int c = 0 ;

    

    c = a < b ? a : b;

    

    //(a < b ? a : b) = 3;

    *(a < b ? &a : &b) = 3;
    

    printf("%d\n", a);

    printf("%d\n", b);

    printf("%d\n", c);

    

    return 0;

}

 

· Ternary operator (a b:? C) return type

  Back b and c by a higher type implicit type conversion rules

  When b and c are not implicitly converted to the same type of the compile error

 

 

Guess you like

Origin www.cnblogs.com/kojull/p/12019663.html