存储器地址“值” [英] Memory address "value"
问题描述
关于指针的快速提问。
写这个试图更好地理解这一点代码:
int * ptr,x = 565;
ptr =& x;
printf(" \ n \ n \ n,x的值是%d \ n",x);
printf(" Now:ptr =& x \ n所以:");
printf(" * ptr的值是%d \ n",* ptr);
printf(&,&,直接ptr应该给出一个地址\" x \" \ n");
printf(Ptr指向x,其地址是%d \ n, PTR); / *<<<<<<<<
返回-1073743224<<< * /
返回0;
}
除了最后一行以外的所有工作......或者确实是内存位置
" -1073743224"
提前致谢。
Quick question about pointers.
Wrote this "trying to understand this better" code:
int *ptr, x = 565;
ptr= &x;
printf("\n\n\nThe value of x is %d\n", x);
printf("Now: ptr= &x\n So:");
printf("The value of *ptr is %d\n", *ptr);
printf("And, straight ptr should give an address of \"x\"\n ");
printf("Ptr points at x whose address is is %d\n", ptr); /*<<<<<<<<
returns -1073743224<<<*/
return 0;
}
All except the last line work...or is the memory location indeed
"-1073743224"
Thanks in advance.
推荐答案
In< 11 ************* *********@h48g2000cwc.googlegroups .commdh < md ** @ comcast.netwrites:
In <11**********************@h48g2000cwc.googlegroups .com"mdh" <md**@comcast.netwrites:
printf(" Ptr指向x,其地址为%d \ n",ptr); / * LT;<<<<<<<
printf("Ptr points at x whose address is is %d\n", ptr); /*<<<<<<<<
除最后一行之外的所有工作......或者确实是内存位置
" -1073743224"
All except the last line work...or is the memory location indeed
"-1073743224"
当你使用%d时,你告诉printf它正在打印一个整数。
但你没有供应整数参数;你使用了一个指针,
哪个不一样。
使用%p打印指针值。 (但是只有无效的指针,所以你要先把b $ b抛到空虚。)
-
John戈登......你作为他的父母和所有人,你有什么,
go****@panix.com 我认为你可以信任他,不要吝啬他。 - Robert Chang,rec.games.board
When you use %d, you''re telling printf that it''s printing an integer.
But you did not supply an integer argument; you used a pointer instead,
which Ain''t The Same Thing.
Use %p to print pointer values. (But only void pointers, so you''ll
have to cast to void first.)
--
John Gordon "... What with you being his parents and all,
go****@panix.com I think that you could be trusted not to shaft
him." -- Robert Chang, rec.games.board
mdh写道:
mdh wrote:
>
关于指针的快速提问。
写这个试图更好地理解这个代码:
int * ptr,x = 565;
ptr =& x;
>
Quick question about pointers.
Wrote this "trying to understand this better" code:
int *ptr, x = 565;
ptr= &x;
[...]
[...]
printf(" Ptr指向x,地址为% d \ n",ptr); / *<<<<<<<<
返回-1073743224<<< * /
printf("Ptr points at x whose address is is %d\n", ptr); /*<<<<<<<<
returns -1073743224<<<*/
[...]
[...]
除最后一行之外的所有工作......或者确实是内存位置
" -1073743224" ;
All except the last line work...or is the memory location indeed
"-1073743224"
可能是。
首先,%d期待一个int,并且你已经设置了一个int *,所以所有的赌注
都是关闭的。但是,鉴于你的帖子说你在Intel Mac上,
,大多数系统可能有sizeof(int)== sizeof(int *)== 4,
它可能在你的平台上好一点。
接下来,%d将值解释为有符号整数,这使得对于一半地址空间的奇怪解释。
最后,-1073743224十进制是0xBFFFFA88十六进制(假设一个32位
签名int),这肯定是一个合理的地址,特别是如果
特定的实现开始堆栈从
开始增长0xC0000000。
-
+ ------------------------- + -------------------- + ----------------------- +
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody / at\spamcop.net | www.fptech.com | < std_disclaimer.h |
+ ------------------------- + --------- ----------- + ----------------------- +
不要 - 邮寄给我:< mailto:Th ************* @ gmail.com>
It could be.
First, "%d" expects an int, and you have pased an int*, so all bets
are off. However, given that your post says you''re on an Intel Mac,
and most of those systems probably have sizeof(int)==sizeof(int*)==4,
it''s probably sort-of okay on your platform.
Next, "%d" interprets the value as a signed integer, which makes for
strange interpretations for half of the address space.
Finally, -1073743224 decimal is 0xBFFFFA88 hex (assuming a 32-bit
signed int), which is certainly a reasonable address, especially if
the particular implementation starts the stack growing down from
0xC0000000.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>
mdh:
mdh:
int * ptr,x = 565;
ptr =& x;
int *ptr, x = 565;
ptr= &x;
虽然我们正在节省空间,但我们也可以写:
int x = 565,* ptr =& ; x;
这也为我们节省了混合声明和语句。
-
Frederick Gotham
While we''re saving space, we may aswell write:
int x = 565, *ptr = &x;
This also saves us mixing declarations with statements.
--
Frederick Gotham
这篇关于存储器地址“值”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!