C++ Comparison of String Literals

You are comparing memory addresses. Apparently your compiler places the string literals in memory in the order it encounters them, so the first is “lesser” than the second.

Since in the first snippet it sees “A” first and “Z” second, “A” is lesser. Since it sees “Z” first in the second, “Z” is lesser. In the last snippet, it already has literals “A” and “Z” placed when the second command rolls around.

Leave a Comment