The trouble is you think you have time. Your success depends on how you utilize your time.

Answer of Dry Run Practice Program # 3 and What are Pre increment and post increment operators in C++

Answer of the Dry Run Practice Program # 3 and what are pre increment and post increment operators:

The Answer is:
3, 2, 15

Answer of dry run practice program no 3

How it Worked ?
For this you have to know about Pre increment and post increment operator, 

So What are Pre increment and post increment operator?

See this to know what is Pre increment operator:

at 7th line,  x=++a[1];
its mean a[1] have element "1", first increment in it and then store it into x.
the a[1] have value "1" after increment in it it become 2 then it stored it x, so now x=2
remember that a[1] is now have 2 also 

See this to know what is Post increment operator:

at 8th line,  y=a[1]++;
its mean a[1] have element "2" (because of the first increment we did in 7th line), first store it into y and then add increment into a[1]. but see the value first stored into y then after that got incremented , so incremented value have nothing to do with y .
so now a[1] have value "3" after increment. and then y=2, and a[1]=3

at 9th line z=a[x++], this is also a statement having  post increment, so the value of  x is 2 it will
stored in z. The index of array "a[x]" is 2 which have 15, then after that it will get increment but it has nothing to do with it. so z =15.


For the Question of this Answer Click Here. 

You Can Also Search This topic by:
Define Pre-increment and Post increment operators.
What are Pre increment and Post increment with examples.


No comments:

Post a Comment