如何在C 中读取/解释复杂的表达式

How to read/interpret complicated expressions in C++

本文关键字:解释 复杂 表达式 读取      更新时间:2023-10-16

类似的东西:

int ctr[], i, distinct = 0;
string s;
distinct += ctr[s[i]]++ == 0; // <-- This line

我了解数组的符号以及哪些增量和减少运算符。我只是不明白这样写的方式。更重要的是,这样写的目的。

它就像以下代码:

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 :)

我希望这对您有帮助。

但是,如果您想编码,则不应像这样编写代码。尤其是如果您想将来阅读代码或希望其他人阅读; - )