What is the result of the following code:
int main() { int k = (k = 2) + (k = 3) + (k = 5); printf("%d", k); }
It makes no mistake, why? I think this should give an error because the assignment operations are on the same line as the definition k.
k
What I mean int i = i;cannot compile. But it compiles. What for? What will be the result and why?
int i = i;
int i = i compiles because 3.3.1 / 1 (C ++ 03) says
int i = i
The declaration point for the name immediately after its full declaration and before its initializer
So, iinitialized with its own undefined value.
i
Undefined , k . FAQ Undefined
int = i; , . C . , , .
C . "10", "k" "a".
, 11. , k 3 , 5 . int k = (k=2)+(k=3) 6, int k = (k=2)+(k=4) 8, int k = (k=2)+(k=4)+(k=5) 13. int k = (k=2)+(k=4)+(k=5)+(k=6) 19 (4 + 4 + 5 + 6).
int k = (k=2)+(k=3)
int k = (k=2)+(k=4)
int k = (k=2)+(k=4)+(k=5)
int k = (k=2)+(k=4)+(k=5)+(k=6)
? . (k = x) , . , k + k, k, , ( k). , ( k ). , k ( ) k .