【发布时间】:2014-11-20 21:49:48
【问题描述】:
我正在尝试学习如何以十进制和十六进制显示指针值。下面你可以看到我创建了一个值并尝试使用指针打印出值和值位置。
请使代码正常工作,以便打印出十进制和十六进制的值
double val= 1;
printf("The value of val : %f\n",val);
double *ptr;
ptr= &val;
printf("dereference *ptr= %f\n", *ptr);
//Display the location of val with and without pointer use in decimal and hex
//decimal
printf("location of val in decimal with ptr is: %p\n",(void *) ptr);
printf("location of val in decimal without a pointer is: %p\n",(void *) &val );
//hexadecimal THIS IS NOT WORKING
printf("location of val in hex with ptr is: %#x\n", (void *) ptr);
printf("location of val in hex without a pointer is: %#x\n", (void *) &val );
【问题讨论】:
-
但是你的问题是什么?
-
我进行了编辑。基本上我需要将指针位置打印为十进制和十六进制,而十六进制不起作用