c++ - Optimized code for two string compare in if condition -


i want 2 string compare , used 2 different if condition. there better way string compare in 1 if condition

if (strcmp(buff1(), config1) == 0) {      if (strcmp(buff2, config2) == 0)     {       // code goes here     } } 

the equivalent code is:

if ((strcmp(buff1(), config1) == 0)) &&     (strcmp(buff2, config2) == 0)) {     // code goes here } 

note: compiler should generate same machine code both code samples. difference cosmetic , aimed @ reader of code.

you difference when add else clauses:

if (strcmp(buff1(), config1) == 0) {      if (strcmp(buff2, config2) == 0)     {       // code goes here     }     else      {         // else 1     } } else  {     // else 2 } 

compared to:

if ((strcmp(buff1(), config1) == 0)) &&     (strcmp(buff2, config2) == 0)) {     // code goes here } else  {     // single else clause } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -