字符串在哪里? [英] where are the strings?

查看:97
本文介绍了字符串在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我知道两次定义之间的区别。

但是我不知道它们在记忆中的位置。

会有人告诉我吗?


char s [] [10] = {" good",morning}; //在堆栈?

char * t [] = {" good"," morning"}; //在堆上?


提前感谢。

解决方案

在文章< 11*********************@z14g2000cwz.googlegroups。 com>,

Thomas Zhu< zh ******** @ gmail.com>写道:

我知道两个定义之间的区别。
但我不知道它们在记忆中的哪个位置。
会有人告诉我吗?
char s [] [10] = {" good"," morning"}; //在堆栈?
char * t [] = {" good"," morning"}; //在堆?




标准C对堆栈或堆没有任何了解。


C中唯一的区别是变量是否是静态的,

auto或者注册。


根据以前的帖子,我认为有真正的C

编译器用于不使用堆栈的实现

或堆。

-

重要的是要记住当它来到法律,电脑

永远不会复制,只有人类复制。计算机给出了

命令,而非许可。只有人才能获得许可。

- Brad Templeton


Thomas Zhu< zh ******** @ gmail.com>写道:

我知道两个定义之间的区别。
但我不知道它们在记忆中的哪个位置。
会有人告诉我吗?
char s [] [10] = {" good"," morning"}; //在堆栈?
char * t [] = {" good"," morning"}; //在堆?




这里的答案是我们不知道 - 它完全依赖于你的实施
。但是,第二个定义中的字符串

可能最终位于与第一个不同的位置;字符串文字

可能存储在一个特殊的内存区域,这可能是也可能不是
是只读的(在任何一种情况下你都不能修改它们) 。


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。


2005-10-27,Thomas Zhu< zh ******** @ gmail.com>写道:

你好,

我知道两个定义之间的区别。
但我不知道它们在记忆中的位置。
会有人告诉我吗?

char s [] [10] = {" good"," morning"}; //在堆栈?
char * t [] = {" good"," morning"}; //在堆上?

提前谢谢。




这两个例子的重要区别在于

前'的字符串是可修改的,而后者则不会。


-

Neil Cerutti


Hello,

I know the difference between the two definations.
But I do not know where are they in the memory.
would someone tell me ?

char s[][10]={"good", "morning"}; // at stack?
char *t[] = {"good", "morning"}; // at heap?

thanks in advance.

解决方案

In article <11*********************@z14g2000cwz.googlegroups. com>,
Thomas Zhu <zh********@gmail.com> wrote:

I know the difference between the two definations.
But I do not know where are they in the memory.
would someone tell me ? char s[][10]={"good", "morning"}; // at stack?
char *t[] = {"good", "morning"}; // at heap?



Standard C does not know anything about stacks or heaps.

The only distinction in C is whether a variable is static,
auto, or register.

Based upon previous postings, I gather that there are real C
compilers out there for implementations which do not use stacks
or heaps.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton


Thomas Zhu <zh********@gmail.com> wrote:

I know the difference between the two definations.
But I do not know where are they in the memory.
would someone tell me ? char s[][10]={"good", "morning"}; // at stack?
char *t[] = {"good", "morning"}; // at heap?



The answer here is "We don''t know" - it''s wholly dependent on your
implementation. However, the strings in the second definition are
likely to end up in a different place than the first; string literals
may well be stored in a special area of memory, which may or may not
be read-only (and you may not modify them, in either case).

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


On 2005-10-27, Thomas Zhu <zh********@gmail.com> wrote:

Hello,

I know the difference between the two definations.
But I do not know where are they in the memory.
would someone tell me ?

char s[][10]={"good", "morning"}; // at stack?
char *t[] = {"good", "morning"}; // at heap?

thanks in advance.



The important difference between the two examples is that the
former''s strings will be modifiable, while the latter''s will not.

--
Neil Cerutti


这篇关于字符串在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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