int i=1,2,3;
int i=(1,2,3);
int i; i=1,2,3;
What is the difference between these statements? I can't get to any particular reason for it.
Statement 1 Result : Compile error.
'=' operator has higher precedence than ',' operator. comma act as a separator here. the compiler creates an integer variable 'i' and initializes it with '1'. The compiler fails to create integer variable '2' as '2' is not a valid indentifer.
Statement 2 Result: i=3
'()' 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.
Statement 3: Result: i=1
'=' operator has higher precedence than ',' operator. so 'i' gets initialized by '1'. '2' and '3' are just constant expression. so have no effect .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With