gpt4 book ai didi

c++ - 当我声明字符串数组时,C++ 如何计算偏移地址

转载 作者:太空狗 更新时间:2023-10-29 19:44:10 27 4
gpt4 key购买 nike

虽然字符串是动态的,所以它没有任何确定的大小,所以当我在 s[0] 之前得到 s[1] 时,C++ 将如何计算它的偏移地址。

例如 int a[2]

0000:1000    a[0]
0000:1004 a[1]

程序:

#include<iostream>
#include<vector>
using namespace std;

int main()
{
string s[2];

cin>>s[1];
cout<<s[1]<<endl;

cin>>s[0];
cout<<s[0]<<endl;
}

最佳答案

字符串数组是字符串对象的数组,它们具有固定大小并且在字符串实际所在的其他地方有效地包含指针

关于c++ - 当我声明字符串数组时,C++ 如何计算偏移地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13287521/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com