lundi 17 octobre 2016

set 2 values in a ternary operation - C

I'm having trouble setting two ints using ternary operators in C. I can't seem to find an answer as most questions relate to multiple ternary conditions.

Whereas, I want to check for one condition and set 2 values accordingly.

Ie:

if ( i == 5 ) {
    x = foo;
    y = foo + 1;
} else {
    x = bar;
    y = bar + 1;
}

so far I tried the following, but it doesn't seem to work.

x, y = ( i == 5 ) ? foo, foo + 1 : bar, bar + 1;

is it possible to set two values in ternary after checking 1 condition?

thanks,

Aucun commentaire:

Enregistrer un commentaire