【发布时间】:2017-01-29 09:00:26
【问题描述】:
我读了一些代码,发现了这个相当神秘的语法:
size_t count = 1;
char *s = "hello you";
char *last_word = "there";
count += last_word < (s + strlen(s) - 1); #line of interest
Count 以某种方式递增。但我认为
【问题讨论】:
-
last_word < (s + strlen(s) - 1);计算结果为 1 或 0(真或假) -
请参阅here 了解有关将布尔值转换为 int 的一些讨论
-
@EuanSmith 这与这里有什么关系?关系运算符返回
int类型的结果。布尔值从何而来? -
当然你在 C 中是对的。我忘记了 C 没有原生布尔类型 - 在 C++ 和 C# 中花费了太长时间。
标签: c addition operator-precedence compound-assignment relational-operators