boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

086-nested-ternary.c (447B)


      1 /* Nested ternary across both arms. */
      2 
      3 int classify(int x) {
      4     return x < 0 ? -1 : x == 0 ? 0 : x < 10 ? 1 : 2;
      5 }
      6 
      7 int main(int argc, char **argv) {
      8     if (classify(-5) != -1) return 1;
      9     if (classify(0)  !=  0) return 2;
     10     if (classify(5)  !=  1) return 3;
     11     if (classify(50) !=  2) return 4;
     12     /* Nested in both arms. */
     13     int a = 1, b = 1;
     14     int r = a ? (b ? 10 : 20) : (b ? 30 : 40);
     15     if (r != 10) return 5;
     16     return 0;
     17 }