Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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;

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

}

1 Answer

0 votes
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)
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.
...