V
Vijay Kumar R Zanvar
Did you know that the following if statement is semantically
right, but could logically be wrong?
if ( i = 2 )
{
/* do something */
}
Tip:
The compiler may only produce a waring: "Possibly incorrect
assignment", but we may ignore it. To avoid such a mistake,
just reverse the two identifiers.
if ( 2 == i )
{
/* do something */
}
If '==' is replaced by an '=', the compiler will give an error
saying "Lvalue required".
right, but could logically be wrong?
if ( i = 2 )
{
/* do something */
}
Tip:
The compiler may only produce a waring: "Possibly incorrect
assignment", but we may ignore it. To avoid such a mistake,
just reverse the two identifiers.
if ( 2 == i )
{
/* do something */
}
If '==' is replaced by an '=', the compiler will give an error
saying "Lvalue required".