我想了解如何以十進制和十六進制顯示指針值。下面你可以看到我創建一個值並嘗試使用指針來打印出值和值的位置。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