c - c中char数组和字符串的内存位置
问题描述
字符串和字符数组存储在哪里?
int main ()
{
int a = 0; //This should be stack
char* p = "hello"; // why this is on the static?
char k[10] = "hello"; //on the stack?
}
一本教科书说char指针(Char * a)将存储在静态上,根据我对“静态内存”的理解,只有这2个会存储在静态内存上:
int a=0;// will on the static
int main()
{
static xxxxx; //will on the static.
}
解决方案
到6.7.8.2,字符串"hello"
inchar *p = "hello"
是字符串文字。
字符串文字通常位于.rodata
, 以防止修改。此外,全局变量位于.data
部分中。
推荐阅读
- pandas - matplotlib pyplot - 如何组合多个 y 轴和多个绘图
- javascript - 我怎样才能知道一个人什么时候开始说话?最好是当他说完ю JavaScript。没有语音识别 API
- css - 使用固定文本在每页顶部添加边距(打印视图)
- swiftui - 当用户在 SwiftUi 中打开应用程序时,如何使对象自动旋转?
- python - 获取值小于 m 的 n 列
- arrays - 尝试在工作表上执行循环,同时将数组中的值粘贴到每个工作表的同一行/列上
- java - 底部导航后退按钮问题
- karate - 空手道似乎只支持密码流程是否有任何验证代码流程的示例或更好的 pkce 验证代码
- path - 运行 JModelica 命令时出现警告(根 MODELICAPATH)
- r - 带有for循环功能的ggplot