C++ 如何阅读/解释C+中的复杂表达式+;

C++ 如何阅读/解释C+中的复杂表达式+;,c++,syntax,expression,C++,Syntax,Expression,大概是这样的: int ctr[], i, distinct = 0; string s; distinct += ctr[s[i]]++ == 0; // <-- This line intctr[],i,distinct=0; 字符串s; 独特+=ctr[s[i]++==0;// 它类似于以下代码: char c = s[i]; distinct = distinct + ctr [x]; // "value +=" is the same as "value = value +

大概是这样的:

int ctr[], i, distinct = 0;

string s;

distinct += ctr[s[i]]++ == 0; // <-- This line
intctr[],i,distinct=0;
字符串s;

独特+=ctr[s[i]++==0;// 它类似于以下代码:

char c = s[i];
distinct = distinct + ctr [x]; // "value +=" is the same as "value = value + ..."

ctr[c]++; // char is used as number here. The c. element in ctr[] is incremented.
//because of c++ instead of ++c the increment is done after all.
distinct == 0 // returns a boolean value into nirvana :)
我希望这对你有帮助


但是如果你想编码,你不应该这样写代码。特别是如果您希望将来阅读您的代码或希望其他人阅读;-)

有人写了这段代码吗?
distinct+=ctr[s[i]]+==0
-出去喊他,看起来有些代码因为源代码级优化而变得模糊了。我想一个好的编译器在AST/汇编级别上也会做类似的事情。它是被定义的行为吗?序列点在哪里?这是垃圾代码。删除它并重写问题是什么?请阅读有关运算符优先级的内容。先做增量运算。比较是最后一个操作。你的回答不正确是的,今晚有点晚了,对不起,你说得对!现在它产生了一个不同的错误(与另一个答案的错误相同)
=的结果是添加到
distinct
的内容,那么我的第一个答案是对的?现在我明天就试试看!第一个答案更接近,但它使用后增量而不是前增量