I came across this code snippet somewhere but cannot understand how does it works:
#include"stdio.h"
int main() {
int j = 1;
+ j += + j += + j++;
printf("%d",j);
return 0;
}
Output:
6
Please explain the working of this code snippet.
I came across this code snippet somewhere but cannot understand how does it works:
#include"stdio.h"
int main() {
int j = 1;
+ j += + j += + j++;
printf("%d",j);
return 0;
}
Output:
6
Please explain the working of this code snippet.
您的程序将无法编译,因为您没有提供lvaluefor 分配。
GCC 显示以下错误消息,
lvalue required as left operand of assignment
在您的程序中,您使用了简写赋值运算符,
例如考虑代码,
a+=b;
方法,
a=a+b;
但是你使用它们的方式是不正确的。
如果我以其他方式编写相同的片段来解释它,我希望您会理解
请注意我的观点 + 变量不过是一个正变量,而 - 变量是负数
现在看看你的片段
#include"stdio.h"
int main() {
int j = 1;
+ j += + j++;// i.e "j+=j++;" which is "j=j+j; j= j+1;"
//now j = j+j "1+1" "j=2" and post increment then j=j+1 "2+1" "j=3"
+j+=+j;//which is j+=j or j=j+j
//hence j=3+3 i.e 6
printf("%d",j);//j=6
return 0;
}