+ 4
Why output of this code is 3?
Just why? (Language: C) #include <stdio.h> int main(void) { int smth = (1, 2, 3); printf("%d", smth); // 3. why..? } https://code.sololearn.com/cZrx2DPFzk4a/?ref=app
2 Answers
+ 2
It is the comma operator
i = a, b, c; // stores a into i
i = (a, b, c); // stores c into i
the differing behavior between the first and second lines is due to the comma operator having lower precedence than assignment.
Also '()' operator has higher precedence than '='. So , firstly, bracket operator is evaluated. '()' operator is operated from left to right. but it is always the result of last that gets assigned.
+ 4
RKK Wow, so fast! Thank you very much!