dry run for the given code ??

+2 votes
asked Sep 20, 2019 by anonymous

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

main( )


int x,y, z;



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


1 Answer

0 votes
answered Sep 21, 2019 by G Abhijit

void main()

int x,y,z;



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
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)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.