Find the output of C Program ?
[pastacode lang=”c” manual=”main()%0A%7B%0Aint%20x%3D20%2Cy%3D35%3B%0Ax%20%3D%20y%2B%2B%20%2B%20x%2B%2B%3B%0Ay%20%3D%20%2B%2By%20%2B%20%2B%2Bx%3B%0Aprintf(%22%25d%20%25d%5Cn%22%2Cx%2Cy)%3B%0A%7D%20%3F%20″ message=”” highlight=”” provider=”manual”/]
While calculating the x value, x & y values are post incremented. So, the values of x & y are added and then incremented i.e. x=56, y=36
While calculating the y value, x & y values are preincremented, so x & y values are incremented and then added i.e x=57, y=37.
{ x=y++ + x++; } equal to
[pastacode lang=”c” manual=”%0Ax%3Dy%2Bx%3B%2F%2F35%2B20%0Ax%2B%2B%3B%20%2F%2F56%0Ay%2B%2B%3B%20%2F%2F36%0A%7D” message=”” highlight=”” provider=”manual”/]
y=++y + ++x; is equal to
[pastacode lang=”c” manual=”%0A%2B%2By%3B%2F%2F37%0A%2B%2Bx%3B%2F%2F57%0Ay%3Dy%2Bx%3B%2F%2F37%2B57%0A%7D” message=”” highlight=”” provider=”manual”/]
Output:
[pastacode lang=”c” manual=”x%3D57%0A%20y%3D94″ message=”” highlight=”” provider=”manual”/]