什么是使用%p [英] Whats the use of %p
问题描述
在printf中使用%p可以进行什么样的格式化
What kind of formating can be done with %p in printf
推荐答案
" Spidey" <是******** @ gmail.com>写道:
"Spidey" <am********@gmail.com> wrote:
在printf中使用%p可以进行什么样的格式化
What kind of formating can be done with %p in printf
无。您可以使用它来打印指针值;输出如何格式化完全取决于实现。
Richard
None. You can use it to print a pointer value; how the output is
formatted is entirely up to the implementation.
Richard
Spidey写道:
Spidey wrote:
在printf中使用%p可以进行什么样的格式化
What kind of formating can be done with %p in printf
打印出一个地址。
例如。
char * p =" abc";
printf(" * abc *的地址)是%p \ n",p);
printf(p的地址是%p \ n,& p);
结果可能be:
* abc *的地址是0x804841c
p的地址是0xbffff474
To print out an address.
eg.
char *p = "abc";
printf("The address of *abc* is %p\n",p);
printf("The address of p is %p\n",&p);
result may be:
The address of *abc* is 0x804841c
The address of p is 0xbffff474
" ROKA" <滚装***** @ gmail.com>写道:
"Roka" <Ro*****@gmail.com> writes:
Spidey写道:
在printf中使用%p可以进行什么样的格式化
What kind of formating can be done with %p in printf
打印出一个地址。
例如。
char * p =" abc";
printf(" * abc *的地址是%p \ n",p);
printf(p的地址是%p \ n,& p);
结果可能是:
* abc *的地址是0x804841c
To print out an address.
eg.
char *p = "abc";
printf("The address of *abc* is %p\n",p);
printf("The address of p is %p\n",&p);
result may be:
The address of *abc* is 0x804841c
The address of p is 0xbffff474
"%p"期望一个void *参数。给它一个char *是好的(但很差
样式恕我直言);给它char **可能会起作用,但严格来说是非b / b
非便携式。
char * p =" abc" ;;
printf(" * abc *的地址是%p \ n",(void *)p);
printf(" p的地址是%p \\ \\ n",(void *)& p);
-
Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>
圣地亚哥超级计算机中心< *> ; < http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
"%p" expects a void* argument. Giving it a char* is ok (but poor
style IMHO); giving it char** is likely to work, but is strictly
speaking non-portable.
char *p = "abc";
printf("The address of *abc* is %p\n", (void*)p);
printf("The address of p is %p\n", (void*)&p);
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
这篇关于什么是使用%p的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!