2016-03-06 87 views
3

我只是編碼比較數組的地址在C++ 11

std::array<std::array<double,3>,27 > dshape; 
&dshape[0][0] points to the address ****780 
&dshape[0][1] points to the address ****788 
&dshape[0][2] points to the address ****790 (I was expecting 796) 

這是爲什麼?

回答

10

(我期待796)

這只是十六進制表示的,不是小數。

所以

0x780 + 0x008 = 0x788 
0x788 + 0x008 = 0x790 

這是爲什麼?

std::ostream& operator<<(std::ostream&, void*)重載會默認打印十六進制值表示。

2

我猜你正在使用cout來輸出地址,因爲它是一個地址,它將在hexadecimal中顯示。

0x790 - 0x788 = 0x08 

它等於:(十進制)

1936 - 1928 = 8