No, that's not a good way to do it, because it doesn't work.
if(*str1==*str2 =='\0')
will get evaluated as:
bool tmp1 = *str1==*str2;
bool tmp2 = tmp1 == '\0';
if (tmp2)
In other words, because the bool will get promoted to an integer, your test will return true whenever the strings start with different characters (tmp1
will be false, which gets converted to 0, and so tmp2
becomes true)
Don't try to outsmart the compiler. Writing fast code is not about writing as few lines of code as possible, or even as short lines as possible. Even if chaining together ==
in this manner was meaningful, there's no reason why it'd be faster. Just write code that you understand, and can write correctly.