积极答复者
一段代码

问题
答案
-
char [] 是一个比较特殊的指针,不允许修改其指向其他地址。所以并没有使得a重新指向了另外的地址,其地址还是指向栈的。
麻烦把正确答案设为解答。
- 已建议为答案 Julian_Xiang 2012年6月15日 8:20
- 已标记为答案 Elegentin XieModerator 2012年6月22日 6:07
-
你好,
这种用法是正确的。正如SplendourG所说的一样,这中方法是把数据存放在栈中,这样的会使得指针a的释放发生在整个程序结束,而不需要我们手动free,而当我们用这种方法:char *a;时free(a);是需要的。具体可以参考:http://blog.csdn.net/hairetz/article/details/4141043(堆和栈),http://stackoverflow.com/questions/419022/char-x256-vs-char-malloc256sizeofchar
希望对你有帮助。
此致
If your question has been solved, please mark the answers and close the post. If not, please feel free to post your questions. With regards.
- 已标记为答案 将死僵尸_fe 2012年6月14日 15:42
- 取消答案标记 将死僵尸_fe 2012年6月15日 6:26
- 已标记为答案 Elegentin XieModerator 2012年6月22日 6:07
全部回复
-
char [] 是一个比较特殊的指针,不允许修改其指向其他地址。所以并没有使得a重新指向了另外的地址,其地址还是指向栈的。
麻烦把正确答案设为解答。
- 已建议为答案 Julian_Xiang 2012年6月15日 8:20
- 已标记为答案 Elegentin XieModerator 2012年6月22日 6:07
-
你好,
这种用法是正确的。正如SplendourG所说的一样,这中方法是把数据存放在栈中,这样的会使得指针a的释放发生在整个程序结束,而不需要我们手动free,而当我们用这种方法:char *a;时free(a);是需要的。具体可以参考:http://blog.csdn.net/hairetz/article/details/4141043(堆和栈),http://stackoverflow.com/questions/419022/char-x256-vs-char-malloc256sizeofchar
希望对你有帮助。
此致
If your question has been solved, please mark the answers and close the post. If not, please feel free to post your questions. With regards.
- 已标记为答案 将死僵尸_fe 2012年6月14日 15:42
- 取消答案标记 将死僵尸_fe 2012年6月15日 6:26
- 已标记为答案 Elegentin XieModerator 2012年6月22日 6:07
-
你好,
鉴于你的第二个问题已经在论坛开设新帖,所以我把这个帖子Mark了,希望您提问有新问题的同时,把老问题正确的答案标记为答案。
谢谢您的理解。
此致
Elegentin Xie [MSFT]
MSDN Community Support | Feedback to us