Why use strcmp instead of == in C++?
问题 I wonder my code works perfectly fine either using strcmp or simply == in C++ for comparing 2 char arrays. Can any one justify the reason of using strcmp instead of == ; 回答1: strcmp compares the actual C-string content, while using == between two C-string is asking if these two char pointers point to the same position. If we have some C-string defined as following: char string_a[] = "foo"; char string_b[] = "foo"; char * string_c = string_a; strcmp(string_a, string_b) == 0 would return true ,