C# 中的一元递增运算符 i++
unary increment operator i++ in C#
在我上次采访中,我发现了这个棘手的问题。
在这两行之后 i.
的值是多少
int i=c;
//c is a constant
i=i++;
其中 c 是一个常量(其中 c 之前已初始化)。请一步一步给我答案,而不是一个字的答案。
最终 i 的值与 c 保持相同。
说明:-
当我被分配 i++;
第 1 步。首先 i++ return 值 c(但未分配给左侧操作数 i)。
第 2 步。然后 i++ 将 i 的值递增到 c+1。
第 3 步。为 i 分配了在第 1 步中 returned 的值 c。
In effect value of i remains same but some where along the execution it
was c+1, But finally it is assigned with value c.
在我上次采访中,我发现了这个棘手的问题。 在这两行之后 i.
的值是多少int i=c;
//c is a constant
i=i++;
其中 c 是一个常量(其中 c 之前已初始化)。请一步一步给我答案,而不是一个字的答案。
最终 i 的值与 c 保持相同。
说明:- 当我被分配 i++;
第 1 步。首先 i++ return 值 c(但未分配给左侧操作数 i)。
第 2 步。然后 i++ 将 i 的值递增到 c+1。
第 3 步。为 i 分配了在第 1 步中 returned 的值 c。
In effect value of i remains same but some where along the execution it was c+1, But finally it is assigned with value c.