-1
#include <stdio.h>
int main(){
    int a=1;
    printf("%d",a += (1,2,3));
        
}

this outputs 4 (i.e a = a + 3 ) can anyone explain why it works that way?

Karl Knechtel
  • 56,349
  • 8
  • 83
  • 124
  • 1
    Because in C, `(1, 2, 3)` means "figure out what `1` is, throw that result away, figure out what `2` is, throw that result away, then figure out what `3` is and use that". The `,`s here represent the "throw that result away" part. This is useful for when the sub-expressions have side effects. This should have been explained to you by whoever gave you the code in the first place. – Karl Knechtel May 28 '22 at 05:23

0 Answers0