首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

如何得到数组元素地址

2013-04-07 
怎么得到数组元素地址int main(){char str[] Hellocout &str endl// 指向str首地址cout &s

怎么得到数组元素地址

int main()
{
    char str[] = "Hello";
    cout << &str << endl;      // 指向str首地址
    cout << &str+1 << endl;    // 想得到第2个元素的地址,结果指向str结束后的首地址
    cout << &str[1] << endl;   // 想得到第2个元素的地址,结果输出字符"ello",不是输出的地址

    system("pause");
    return 0;
}

[解决办法]
cout << (unsigned int)&str[1] << endl;

热点排行