943,762 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 915
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 4th, 2008
0

Re: what is the execution sequence of this code?

Mr, Ancient Dragon
take it easy, I don't mean that, I just wanted to know how can I make it with myself.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
ALAZHARY is offline Offline
14 posts
since Jul 2006
Dec 4th, 2008
0

Re: what is the execution sequence of this code?

Like I said before, do whats in the inner-most parentheses first, then work yourself out. Once you have removed all parentheses, work the statement from left to right.

For example: a - ((b * c) / d) + e; First calculate b*c, then divide that result by d, finally subtract that result from the value of a and add e.

f = b * c;
now the equation will look like this: a - (f / d) + e

g = f / d; ===> a - g + e
Last edited by Ancient Dragon; Dec 4th, 2008 at 9:00 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Dec 4th, 2008
0

Re: what is the execution sequence of this code?

Thank you for you and everyone.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
ALAZHARY is offline Offline
14 posts
since Jul 2006
Dec 4th, 2008
0

Re: what is the execution sequence of this code?

Anciant Dragon has given the answer of question you've asked, you asked for What is the Execution Sequence you didn't ask How to find out the execution sequence.

Let me teach you how to find it out.
cpp Syntax (Toggle Plain Text)
  1. void EatSpace(char* Pbuffer)
  2. {
  3. int i = 0;
  4. int j = 0;
  5. while((*(Pbuffer + i) = *(Pbuffer + j++)) != '\0')
  6. if (*(Pbuffer + i) != ' ')
  7. i++;
  8. }

when the above funciton is called, Compilers will push the PTR Puffer on stack then push the Local variables i and J on the stack.
now the interesting part.

while((*(pbuffer+i) = *(pbuffer + j++)) != 0)
assignement operator are evaluatted from right to left.
so the above code can be broken as follows
*(pbuffer + j++) the above expression is evaluated as follows
C++ Syntax (Toggle Plain Text)
  1. take the address of pbuffer add j to its contents and derefer the complete value. increment the j for next execution

you will get some character in that case aren't you?
assign that character to lvalue which is
*(pbuffer + i) you can break the above statement now,
lets say right value calculated as 'C' you assign it to left handside so the right handside become 'C' as well which is not equal to '\0'
isn't it
always remember one thing there is still a world ahead
a more better explanation can be provided to you but the thing is that you don't know the assembly and compilers. Sometimes experts like Anciant Dragon doesn't explain the very minor details because either they are irrelevant to you or more advance so that you can't grasp them. be patient just take a hint and dig it out yourself one day you'll learn why Anciant doesn't tell you the complete story.
Reputation Points: 113
Solved Threads: 20
Junior Poster
Laiq Ahmed is offline Offline
147 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Triangle made with numbers from 1 to 9
Next Thread in C++ Forum Timeline: Help Need for Resolving a C++ error C2664





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC