Thank you SamuraiCrow.
Pointers, being a relatively easy type in concept, can cause many hazards (at least i find myself more cursing at them then they do good for me) :-)
Although the following question is perhaps more related to operators (and their precedence), i found myself rather puzzled at the following snippet:
while ((*ptr ++ = *orig ++));
Where orig is a * char (ergo null terminated) passed to a function and ptr holding a copy of that passed * char (memory was allocated for that using strlen + 1).
Seeing that, i am able to analyze (in pascal-ish form):
- ptr^ := orig^; // copy single character from orig to ptr
- inc(ptr); // next ptr position in memory
- inc(orig); // next orig position in memory
I do notice that the 'copy' statement is placed inside extra brackets, so that the statement produces a while condition that evaluates to be either true or false.
But, for the life of me, i can't seem to figure out when/why that while loop ends (yes i can run it and see, but am not able to evaluate it theoretically) :-S
Is that related to pointer, operator and/or while loop behaviour, or otherwise compiler/language specific behaviour ?
How is one able to figure out the answer(s) to the questions that arises from such (relatively small) topics ?
F.i. i've tried to understand operator precedence, but the tables from existing documentation, only seems to contradict itself (imo that is). Mentioning left-to-right, right-to-left is all nice, but when using larger statements, a simply soul like myself gets lost between choosing left or right :-S.
(if the above is not in sync with your tutor, then please ignore. no need to derail, although i do would like to understand the while loop condition, especially if related to pointer operation).