Dereferencing a pointer multiple times vs creating temp variable

Viewed 979

I had a while loop looking like:

while (str[i] != *p)
    ++i;

and a friend popped over and mentioned that it would be faster to do:

char c = *p;
while (str[i] != c)
    ++i;

I guess the question is:

if I dereference a pointer multiple times, at what point does it become faster to create a temp variable.

3 Answers
Related