Is it still valid and good practice in C++11 write if clause like
int i;
//some code
if (i) //some code
or it is preferred to write
if(i != 0)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is well-defined behaviour, so you can use the shorter expression. It might seem cryptic for a non-experienced developer, but regulars shouldn’t have problems in understanding it.
It might have some sense to use the longer form when explicitly treating
ias a number, and omitting it when it has some other logical meaning.