I am finding that adding or subtracting "one" to a pointer is actually adding the number of bytes that is allocated to the pointer type. To find the next value in memory, I thought I should add the number of bytes to the pointer:
//should be next variable in memory?
pointer = pointer + sizeof(pointer);
but that was skipping over data. I found when I add "one":
pointer++; //this works, but shouldn't?
then I got the data I wanted (in this case, 8 bytes forward).
This should display the memory address of one array element, and then you'll see that the next output is 8 bytes more.
Maybe this is supposed to be the way it works, but I don't think so...
Code:void main() { double m_dValue[10]; double *m_pValue; CString size; m_pValue = & m_dValue[0]; //this shows address "6618360" on my PC size.Format("%d",m_pValue); AfxMessageBox(size); //this shows address "6618368" on my PC size.Format("%d",m_pValue+1); AfxMessageBox(size); }



LinkBack URL
About LinkBacks


