4,735 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

870
views
1 answers
2 votes
Jason asked Mar 1, 2018
870 views
#include <stdio.h> #include <iostream> using namespace std; int main() { printf("Hello World"); int a = 10, b = 20, c= 30, d = 40; int e = ++a || ++b || ++c && ++d; // ... b = 20 c = 31 d = 41.but the output is a = 11 b = 20 c = 30 d = 40
5.5k
views
1 answers
1 votes
nish kim asked Sep 2, 2017
5,480 views
{double b =5 & 3 && 4 || 6 | 6 ;printf("%lf",b);}a.2.000000b.1.0c.1.000000d.compilation error
1.3k
views
3 answers
2 votes
radha gogia asked Mar 19, 2018
1,328 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 ... although they are defined at the same level .So what conclusion can be drawn from this ?
384
views
2 answers
0 votes
Sk Jamil Ahemad asked Feb 1, 2022
384 views
Please explain with some example that How Right to Left associativity takes place in case of Ternary operators?