2016-03-06 92 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