Saturday, July 16, 2011

C++ Pointers (use of pointer)?

It depends what you want to do with it. If that pointer is always going to point to the head of that particular array, then you could just as easily use the array itself, adding the & symbol if you ever want to get a memory address. In the real world, though, often we allocate memory for a pointer, then later allocate other memory somewhere else and switch the pointer to point to that instead, and other parts of the program logic may use that same pointer without needing to know whether it was reallocated. We might also increment a pointer in order to traverse an array.

No comments:

Post a Comment