指针的概念 [英] pointer concept

查看:77
本文介绍了指针的概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


char * p =" str";


将为此分配多少内存。

Hi All

char *p="str";

How much memory will be allocated for this.

推荐答案

gsingh说:
gsingh said:

大家好

char * p =" str";


将为此分配多少内存。
Hi All

char *p="str";

How much memory will be allocated for this.



字符串文字至少有四个字节,

指针的字节大小为p字节。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

At least four bytes for the string literal, and sizeof p bytes for the
pointer.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


我相信会有4个字节('s'','t'',''r'',''\\ \\ 0'')为字符串分配了

,并为指针分配了sizeof(char *)(这将在不同的系统上变化
)(指针的大小,虽然,无事可做

与where.or指的是它所指的是多少空间)


欢呼


10月29日凌晨1点34分,gsingh< gs.alca ... @ gmail.comwrote:
I believe that there will be 4 bytes (''s'', ''t'', ''r'', ''\0'') allocated
for the string, and sizeof(char*) for the pointer (that will vary on
different systems) (the size of the pointer, though, has nothing to do
with where.or how much space the thing it is pointing to is/takes)

cheers

On Oct 29, 1:34 am, gsingh <gs.alca...@gmail.comwrote:

Hi All

char * p =" str";


将为此分配多少内存。
Hi All

char *p="str";

How much memory will be allocated for this.



Richard Heathfield写道:
Richard Heathfield wrote:

gsingh说:
gsingh said:

>大家好

char * p =" str" ;;

将为此分配多少内存。
>Hi All

char *p="str";

How much memory will be allocated for this.



字符串文字至少有4个字节,

指针的字节大小为p字节。


At least four bytes for the string literal, and sizeof p bytes for the
pointer.



为什么至少 ?对齐约束?

sizeof是否包含因对齐而需要的任何字节数?


- Larry

Why "at least" ? Alignment constraints?
Does sizeof include any byte-count required because of alignment?

- Larry


这篇关于指针的概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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