C表达式s[i++]=t[j++]如何完全按顺序工作?
我是 C 新手,一直在理解表达式s[i ++] = t[j ++],我不知道如何使用变量访问数组元素,然后变量自身增加,然后再次使用原始变量访问刚刚访问的数组元素然后被分配到另一个数组的元素,我很困惑,我认为了解确切的过程可能涉及一些低级知识,但我不想离题太远,有什么方法可以轻松理解它清楚地?
回答
In C language, the expression i++ causes i to be incremented, but the expression i++ itself evaluates to the value i had before being incremented. So the expression s[i++] = t[j++] has the same behaviour as:
s[i] = t[j];
i = i + 1;
j = j + 1;
except that the precise order is not specified. For that last reason, the rule is that a variable should only be modified once: s[i++] = t[i++] would invoke Undefined Behaviour.