I understand that if you have 'cat' (string1) and 'dog' (string2) in strcmp (this is a C question) then the return value of strcmp would be less than 0 (since 'cat' is lexically less than 'dog').
However, I am not sure what would happen with strcmp if this happened:
string1: 'dog'
string2: 'dog2'.
What would strcmp return? Less than zero, zero, or greater than? For context, I am trying to write a comparator function that compares strings and would like to account for strings starting with the same characters. One string may have an extension (such as '2' in 'dog2' in the example above).
EDIT: This is not a duplicate question. The question that this is allegedly similar to asks what the return type represents - I am saying what happens when the strings are identical up to a point but then one of them stops whilst the other continues.
sizeof(int)
that is dependent on the implementation? It's still consistent, as it works as specified in the formal C standard. Strings, and their behavior, is consistent between platforms and implementations, but I'll give that the character encoding can differ, but the behavior of strings and character and string functions is still consistent. – Cosmetician