LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   adresses in array (https://www.linuxquestions.org/questions/programming-9/adresses-in-array-843704/)

vbx_wx 11-11-2010 11:21 AM

adresses in array
 
Code:

        int main()
{
        double numbers[10] = {0.0,1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9};
        double* nPtr = &numbers[0];

        cout << numbers << endl;
        cout << nPtr + 1 << endl;
        cout << nPtr + 2 << endl;
        cout << nPtr + 3 << endl;
        cout << nPtr + 4 << endl;
        cout << nPtr + 5 << endl;
        cout << nPtr + 6 << endl;
        cout << nPtr + 7 << endl;
        cout << nPtr + 8 << endl;
        cout << nPtr + 9 << endl;

}

OUTPUT:
Code:

0xbf92e408
0xbf92e410
0xbf92e418
0xbf92e420
0xbf92e428
0xbf92e430
0xbf92e438
0xbf92e440
0xbf92e448
0xbf92e450

I am confuse why my memory adresses are not from 8 to 8 bytes. Can someone explain why ? Thank you

rupertwh 11-11-2010 11:30 AM

Quote:

Originally Posted by vbx_wx (Post 4155917)
... why my memory adresses are not from 8 to 8 bytes.

If by 'from 8 to 8 bytes' you mean what I think you mean, they are. I.e. each line's number is the previous plus 8.

graemef 11-11-2010 07:47 PM

Remember the address is printed in hexadecimal format (base 16) so the addresses are each 8 bytes long and are on zero or eight byte boundaries.

lesca 11-12-2010 11:05 PM

The size of double is 8 byes.

The output base is 16, digits are from 0 to 9 and a to f.

0x00 + 0x08 = 0x08 (8 in Dec)
0x08 + 0x08 = 0x10 (16 in Dec)

Hope my explanation may help you.


All times are GMT -5. The time now is 04:21 PM.