My question is that how will strcmp()
handle the following case:
strcmp("goodpassT", "goodpass");
I read that the comparison continues until a different character is found or null character (\0
) is found in any of the strings. In the above case, when it encounters \0
for the second argument, will it just stop comparison, or will it still compare to the T
character ? The return value is 1, but I'm not sure about the stopping condition.
The comparison is done using unsigned char. Thus the shorter string is smaller as its terminating 0 is smaller than other unsigned nonzero char in the longer string. See http://port70.net/~nsz/c/c11/n1570.html#7.24.4p1