# dry run for the given code ??

What is the output of the following program with explaination of each step

main( )

{

int x,y, z;

x=2;

y=5;

z= x+++y;                                                           //here x remian same adn must be increment

printf(%d %d %d, x, y z);                                  //output will be x=3,y=5,z=8 according to me                                                                                    //but when i run the program z =7 whyy

}

answered Sep 21, 2019 by G Abhijit
#include<stdio.h>

void main()
{

int x,y,z;

x=2;

y=5;

z= x+++y;                                       //z= x++ + y.... x inc by 1 after addition
printf("x=%d y=%d z=%d", x, y, z);                //output will be x=3,y=5,z=7
x=2;
z= ++x+y;                                       //z= ++x + y.... x inc by 1 make addition..result according to your result
printf("\nx=%d y=%d z=%d", x, y, z);               //according to your assumption...output will be x=3,y=5,z=8
}
commented Sep 21, 2019 by anonymous
here y is pre increment ??(x+++y) so first value increment then evaluate then y will become 6  during the addition of the number(z)