4,706 views
2 votes
2 votes
The output of the following program

main ( )

{

int a = 1, b = 2, c = 3;

printf (“%d”, a+ = (a+ = 3, 5, a));

}

1 Answer

2 votes
2 votes
this is an effect of comma operator, i.e the last element is the one that is used as the value.

a+=(a+=3,5,a)

this expression evaluates a+=3 first which makes a = 4 , this result gets discarded then evaluates 5 which is also discarded and then evaluates a  which is the last element so the result we get is

a+=4

which gives 8 as the output

Related questions

2 votes
2 votes
1 answer
1
1 votes
1 votes
1 answer
2
nish kim asked Sep 2, 2017
5,451 views
{double b =5 & 3 && 4 || 6 | 6 ;printf("%lf",b);}a.2.000000b.1.0c.1.000000d.compilation error
2 votes
2 votes
3 answers
3
radha gogia asked Mar 19, 2018
1,282 views
If I have the grammar :E->E*F | F+E |FF->id ,Now here although + and * are defined at the same level , with different associativity but this grammar produces 2 different ...
0 votes
0 votes
2 answers
4
Sk Jamil Ahemad asked Feb 1, 2022
371 views
Please explain with some example that How Right to Left associativity takes place in case of Ternary operators?