我想了解如何以十进制和十六进制显示指针值。下面你可以看到我创建一个值并尝试使用指针来打印出值和值的位置。C指针位置,十进制和十六进制
请正确使代码工作,以便打印出以十进制和十六进制值
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);
但是,您的问题是什么? – 2014-09-26 00:21:50
我做了编辑。基本上我需要打印指针位置作为十进制和十六进制,并且十六进制不起作用 – 2014-09-26 00:27:09