A string is not a magic object that understands what it contains and acts differently on it.
In your case, you are comparing the address that hold a buffer of chars (containing '3', '5', 0) with the address containing another buffer of chars (containing '2', '3', '5', 0).
The output is random (in fact, it isn't, but for now, let's assume it is).
If you want to compare strings, you can use the second example (or strcmp
) but that will compare the buffer content based on some logical rules, that are not those you except (you expect semantic logic, but it's not).
The rules are:
- Compare each buffer char based on their ASCII/Unicode order, and return -1 if the first one is lower than the second one, 1 if it's higher. (If using
<
operator, it returns true if -1, false otherwise and so on)
- If they are equal, continue to next char.
In the previous example, '3' is higher than '2' (even if 35 is smaller than 235).
You'll need to either convert your string to integer before comparing (and deal with potential conversion errors) or use integers from the beginning.