But in case of pointers, multiple trips are required to the RAM from CPU to get a value.
That's simply not true. For example, consider this. Even though *p is in a loop, the compiler reads the value once and is clever enough to convert the loop into a multiplication. Even in a simpler case like:
int n = *p;
n += *p;
the compiler will still read from *p only once because it assumes that there are no data races. (If your program is single-threaded, then there can't be any data races; if your program is multi-threaded and there are data races, then your program has undefined behavior and the compiler isn't responsible.)
I don't know where you got the idea that reading from a pointer requires multiple trips to RAM; but in the future, I respectfully suggest that perhaps you should really be 100% sure about a topic before writing about it and spreading incorrect information.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
By the way:
That's simply not true. For example, consider this. Even though
*pis in a loop, the compiler reads the value once and is clever enough to convert the loop into a multiplication. Even in a simpler case like:the compiler will still read from
*ponly once because it assumes that there are no data races. (If your program is single-threaded, then there can't be any data races; if your program is multi-threaded and there are data races, then your program has undefined behavior and the compiler isn't responsible.)I don't know where you got the idea that reading from a pointer requires multiple trips to RAM; but in the future, I respectfully suggest that perhaps you should really be 100% sure about a topic before writing about it and spreading incorrect information.