Search Ali's Blog

Friday, October 13, 2006

operator "=" rc

After a long discussion with my brothers on the returned code of operator "=", Unsurprisingly, I was wrong, and it seems that the returned code of (a=b) in cpp is "a" by reference (and not by value as I thought).
simply run the following code by g++ to make sure:

#include
int main() { int b; (b=5)++; printf("b=%d\n", b); return 0; }


Surprisingly, the output is b=6.

What about ANSI C?! hmm, it seems that the rc of (a=b) in C is "a" by value, thus the code won't compile.

No comments: