| | |
what is the execution sequence of this code?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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:
f = b * c;
now the equation will look like this:
g = f / d; ===>
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jun 2006
Posts: 147
Reputation:
Solved Threads: 20
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.
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.
assignement operator are evaluatted from right to left.
so the above code can be broken as follows
you will get some character in that case aren't you?
assign that character to lvalue which is
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.
Let me teach you how to find it out.
cpp Syntax (Toggle Plain Text)
void EatSpace(char* Pbuffer) { int i = 0; int j = 0; while((*(Pbuffer + i) = *(Pbuffer + j++)) != '\0') if (*(Pbuffer + i) != ' ') i++; }
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)
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.
![]() |
Similar Threads
- Help With syntax (Visual Basic 4 / 5 / 6)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- xmlDoc.onload problem, sequence of execution for Firefox (JavaScript / DHTML / AJAX)
- Timing Execution (C++)
- ajax refresh?? (JavaScript / DHTML / AJAX)
- blank pop-ups (Viruses, Spyware and other Nasties)
- Printing binary (C++)
- pygtk Glade GUI freezes (Python)
Other Threads in the C++ Forum
- Previous Thread: Triangle made with numbers from 1 to 9
- Next Thread: Help Need for Resolving a C++ error C2664
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






