mercredi 26 juillet 2017

Single-line if statemets in C - which statements are affected?

I'm trying to translate some code from C to another language. I don't have a quick access to a C compiler and just found myself confused with the single-line if statements. I know that statements like:

if (condition) [statement]

and

if (condition)
    [statement]

can be evaluated without the brackets, i.e. ar equivalent to:

if (condition) {[statement]}

and

if (condition)
    {[statement]}

respectively, but I'm not sure about the sample code I'm dealing with. It goes:

if (ge.g[*l][*k].s==1) *i=1; else *i=Ne;  
*j=*l; 

I feel like the second line is not affected by the if statement, but it's not immediatelly obvious from the context of the code. Long story short: is the above equivalent to:

if (ge.g[*l][*k].s==1) {*i=1;} else {*i=Ne;}  
*j=*l; 

or

if (ge.g[*l][*k].s==1) {*i=1;} else {*i=Ne;  
*j=*l;} 

?

Aucun commentaire:

Enregistrer un commentaire