C - pointer arithmetic
c, pointers
Solution
in the first code `p` is incremented regardless of if the `while()` condition was true or false.
In the second snippet of code, `p` is incremented ONLY if `while` condition was true.
Problem
In the following code: ``` int strlen(char *s){ char *p = s; while(*p++ != '\0'); return p - s; } ``` Why does the above evaluate differently than this: ``` int strlen(char *s){ char *p = s; while(*p != '\0') p++; return p - s; } ``` It is my understanding that the expression will evaluate first, and then increment.