in code A using pr e- decrement therefore i gets decremented when checking while condition so it will print as 9 8 7 6 5 4 3 2 1 ..... in code B using post-decrement it will prints like 9 8 7 6 5 4 3 2 1 0 here why zero printing means while checking while condition x-- have previous value..therefore at tht time x-- is 1 so while condition executing and prints x value as zero.
On 7/21/11, Reynald <[email protected]> wrote: > Code: A > int main() > { > int x = 10; > while ( x = --x) > printf( " %d ", x); > getchar(); > } > > Code: B > int main() > { > int x = 10; > while ( x = x--) > printf( " %d ", x); > getchar(); > } > > Does Code-A and Code-B work similar? Justify. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
