哪里是内存,一个const char指针分配呢? [英] Where is memory allocated with a const char pointer?

查看:150
本文介绍了哪里是内存,一个const char指针分配呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/349025/is-a-string-literal-in-c-created-in-static-memory\">Is字符串在C ++字面静态内存中创建?结果
   C ++字符串数据类型存储

在此code:

为const char *海峡=Hello World的;

如果我理解正确的指针是4或8个字节,这是我的猜测是在栈上分配。
但如果是为Hello World的分配,并存储在存储?结果
或者什么呢 STR 指出确切地?

If I understand correctly a pointer is 4 or 8 bytes, which I guess would be allocated on the stack. But where is the memory for the "hello world" allocated and stored?
Or what does str point to exactly?

推荐答案

这不是分配。它一般存放在你的程序的code段或堆栈这是到编译器上。无论哪种方式,它指向字符的空终止数组。

It's not allocated. It's generally stored in your program's code segment or on the stack That's up to the compiler. Either way, it points to a null-terminated array of characters.

这篇关于哪里是内存,一个const char指针分配呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆