且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++字符串字面量比较

更新时间:2023-11-06 20:04:16

您正在比较内存地址。显然,你的编译器将字符串字面量放在内存中的顺序遇到他们,所以第一个是较少比第二个。

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.

因为在第一个片段它看到 A第一和Z秒,A较小。由于在第二个中看到Z,Z较小。在最后一个片段中,当第二个命令滚动时,它已经放置了字母A和Z。

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.