Hi,
This is probably been asked here before...but:
what is faster ?
this:
Code:
int main()
{
int n[] = {1,2,3,4,5,6,7,8,9,10};
int *p = n;
int i;
for(i = 0; i < 100; i++){
printf("\n%d",*(p+4)*i);
}
return 0;
}
or this:
Code:
int main()
{
int n[] = {1,2,3,4,5,6,7,8,9,10};
int *p = n;
int i;
int j = *(p+4);
for(i = 0; i < 100; i++){
printf("\n%d",j*i);
}
return 0;
}
now let's say that i have a function that needs to dereference a pointer millions of times , in order to get it's value.
would it be better to just dereference it once and store the value into a local variable and just use that variable ? will it be faster ?
but specific to my function, using the pointer dereference style would result in a cleaner and a little simpler code, and also save me a variable (like int j in the above example).
Thx.