# Dynamic Arrays

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 10-03-2001
WebSnozz
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[0] is 007D0C70
Value pInt[1] is 007D0C74
Value pInt[2] is 007D0C78
Value pInt[3] is 007D0C7C
Value pInt[4] is 007D0C80
Value pInt[5] is 007D0C84
Value pInt[6] is 007D0C88
Value pInt[7] is 007D0C8C
Value pInt[8] is 007D0C90
Value pInt[9] 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:

int *pointerName;

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:
int x=5;
cout<<*&x;//outputs 5

PS. Is each element taking up four addresses?
How much memory is in an address, a byte?
• 10-03-2001
Nick
Each int is 4 bytes.
• 10-03-2001
WebSnozz
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?
• 10-04-2001
gliptic
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.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12