*(temp + count) = *(foo + i);
The + operators perform pointer arithmetic. Adding an integer to the value of the pointer gives a new pointer, increasing the specified number of objects behind the original pointer. For example, if p is a pointer to arr[0] , then p+2 points to arr[2] .
The * operator removes the resulting pointer, giving you the object it points to.
In fact, the array indexing operator [] is defined in terms of pointer arithmetic, so A[i] means *(A+i) (ignoring operator overloading). Therefore, the above line of code:
*(temp + count) = *(foo + i);
can also be written (more clearly IMHO) as:
temp[count] = foo[i];
You might want to read the comp.lang.c FAQ , specifically sections 4 (Pointers) and 6 (Arrays and Pointers). Most of the information is also applicable to C ++.
However, C ++ provides higher-level libraries, which can be more reliable than low-level C equivalents. In C ++, the idea of ββwriting code that is directly related to arrays and pointers to array elements rarely arises, unless the very low level of code and performance are critical and / or you are dealing with data structures from C code.
source share