Ambiguous condition in if statement

if ( x == 0 )
if ( 0 == x)
consider both the cases what is potential bug in first statement and how second statement is better?

Comments

  1. potential bug in first statement...

    if ( x == 0 ) // if we forget and make it single =, it becomes x = 0, and the bug is severe that cant be found so easily unless we have eagle eyes :)

    so second statement is better.

    ReplyDelete
  2. @B Ramesh yeah very true and if we make it single = in second statement it will give error.(invalid lvalue in assisgment).

    ReplyDelete

Post a Comment

Popular posts from this blog