[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [LCP]which one first?



> here is a following code have a look,
>
> for(i = 0; buf[i] != ' ' && buf[i] != '\0'; value[i] = buf[i], i++);
>
> which statement will execute first
> value[i] = buf[i] or
> i++
> please give reasons.
>
Mehul,

1) value[i] = buf[i]  will be done first

2) It's a "comma expression". There are two (very different) uses of the
symbol ',' in C. When it is used between the parameters of a function
call it does NOT guaranteee anything about order of execution. But when
used between terms of an expression.....
  {expr1 , expr2, ........, exprn}
    then you are guaranteed that:
    a) they will execute in that order
    b) the value of the entire thing will be the value of exprn

Mike