Hi,
My question is why add array_size + my_array? Why not just array_size? |
If you were to print out the value of
my_array
, you would see that it is a pointer and it's value is the memory address. When one does pointer arithmetic, the compiler knows the size of 1 element, so when you add a number
n
to an address, it can calculate the address of the
n
'th element in the array. So
my_array + array_size
is the address of the last element in the array. Without that sum, we have
0 + array_size
, which is certainly invalid.
So all that was for when you use pointers and pointer arithmetic. The second part of my code shows how to do it without pointers.
It is good to learn about raw pointers, especially for C Programming, but in C++ they are discouraged. One can do lots of things just using the STL containers and algorithms, if you really need a pointer, then consider smart pointers - read up about
unique_ptr
. Boost is really worth looking at, I am fooling around with their
mpl
and units stuff at the moment.
Iam using Eclipse IDE - do you think its debugger is alright to work with?
|
I am sure it will be fine. To get at it, either click the
Debug
button at the top right of the window, or use the menu: Window, Open Perspective, Debug. I have Eclipse Kepler (along with 3 other IDE's), so hopefully your layout is similar.
Regards :+)