0

What will be output ? And what is that bracket operator?

https://code.sololearn.com/c3bw4496Nm9t/?ref=app

26th Aug 2020, 5:44 AM
Gaurav Kamble
Gaurav Kamble - avatar
12 Answers
+ 4
I can give another example hope u will understood much better. Everything in the parenthesis is operated first from left to right it is read like this Int k=-5; Int a=(k++,++k); a= (-4,-3); a=-3; After reading everything inside parenthesis last value was -3 so its was assign to a and output is -3
26th Aug 2020, 6:07 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Actully u have not write code proper it giving errors U wrote like this in line 8 which is completely wrong d(a++ ,b ,a ); this means u calling function and u not defined function definition so how it will be call .here u should write like this d=(a++ ,b ,a ); If u print value of d theñ Output will be 2 always last VALUE will be print it behave like Stack first u push value of a which is 1 after then u use post increment here value will increase so( a) will be 2 and after u pushing b then u write a so last value will be print and a was 2 becoz it was incresed a++ before insert of b
26th Aug 2020, 5:53 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Gaurav Kamble its working properly try in other ide or compiler its giving warnings only read what errors showing comman has no effect . Its just warning.
26th Aug 2020, 6:05 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
26th Aug 2020, 6:11 AM
Gaurav Kamble
Gaurav Kamble - avatar
+ 2
Aniket was right, variable <d> can be initialized by multiple values, each expression inside the parentheses () will be evaluated, but in the end, only the last expression in the parentheses will be used as the value to be assigned for <d>. To understand this behaviour, have a look at this http://www.c4learn.com/c-programming/c-comma-operator/
26th Aug 2020, 6:05 AM
Ipang
+ 2
Gaurav Kamble đŸ€ŁđŸ˜‚đŸ˜‚đŸ˜„đŸ˜‡ Thankyou
26th Aug 2020, 6:14 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
The code has error. What bracket operator? which line?
26th Aug 2020, 5:49 AM
Ipang
+ 1
But it runs in other compilers . Bracket operator on 8th line I don't have any idea how it works. @Ipang
26th Aug 2020, 5:53 AM
Gaurav Kamble
Gaurav Kamble - avatar
+ 1
Gaurav Kamble Did you mean something like this: #include <stdio.h> int main() { int a=1 , b=3 , d; d = (a++ ,b ,a ); printf ("%d",d); return 0; }
26th Aug 2020, 5:59 AM
minirkk
minirkk - avatar
26th Aug 2020, 6:13 AM
Gaurav Kamble
Gaurav Kamble - avatar
26th Aug 2020, 5:55 AM
Gaurav Kamble
Gaurav Kamble - avatar
0
Still it's not running but the answer is 2 rkk
26th Aug 2020, 6:03 AM
Gaurav Kamble
Gaurav Kamble - avatar