i was given the code:
#include <stdio.h>
int main(void) {
int a = 0, b = 0, c = 0;
c = (a -= a - 5), (a = b, b + 3);
printf("a = %d, b = %d, c = %d", a, b, c); // a = 0, b = 0, c = 5
}
and my task was to figure out how it works. i do not understand how the line
c = (a -= a - 5), (a = b, b + 3);
works, though.
my guess is that it works just like this code:
#include <stdio.h>
int main(void) {
int a = 0, b = 0, c = 0;
a -= a - 5;
c = a;
a = b;
b + 3;
printf("a = %d, b = %d, c = %d", a, b, c); //a = 0, b = 0, c = 5
}
because the result is the same.
but i don’t understand the first version of the code. so firstly, in changes the value of a (a becomes 5), then changes the value of c (c becomes a), and then in performs the expression in the second parantheses (which seems to not affect the value of c at all, although it’s the same line of code and there was no semicolon in between, only a comma. what is that syntax? is there a name for that kind of syntax? i just don’t understand why it was written like that and why it does what it does.
also, less importantly, what does the line
b + 3;
do? is it just nothing?..