I was playing with ripper's code and if I change it so that it outputs the address instead of the value by taking the * off of pIncre, then pIncre++ increments the address by 4,
Value pInt is 007D0C70
Value pInt is 007D0C74
Value pInt is 007D0C78
Value pInt is 007D0C7C
Value pInt is 007D0C80
Value pInt is 007D0C84
Value pInt is 007D0C88
Value pInt is 007D0C8C
Value pInt is 007D0C90
Value pInt is 007D0C94
Press any key to continue
Why is this?
How does it process arithmetic operations on a pointer?
I want to make sure I've got pointers straight, cause they are weird to me. For example:
My understanding of a pointer was that the "int" is related to the type of data that is in the memory location. And the "*" says that pointerName is a variable that can store a alphanum value such as "007D0C70".
, and you use the * operator to evaluate it as the value at that memory address like:
PS. Is each element taking up four addresses?
How much memory is in an address, a byte?
Ok, that's kinda what I thought.
But I'd think pIncre++ would take the memory address and add 1 to it. How does the ++ operator know to add 4 instead of 1?
When you add a value to a pointer in C++, you actually adds the value times the size of the datatype the pointer points at. If you want to add one to a pointer you can cast it like this:
int *pnt = new int;
pnt = (int*)(((char*)pnt)+1)
This is one of the reasons I like assembler better than C++, it's more logical and you see exactly what is happening.