该程序是在solaries的工作站上运行的。我想要输入一个16进制表示的浮点数,然后转换成16进制的整数。
程序结果是正确的。问题是程序运行结果如下:
put in a single float:c0800000
q is ffbeee00
p is ffbeee00
*p is c0100000
*q is c0800000
***********************************
result is fffffffc
p和q指向同一个地方,为什么输出的内容不一样呢?
原程序
int main(int argc,char **argv)
{
float * p;
// double *pd;
unsigned long int *q;
unsigned long int input;
unsigned long result;
//static char ch,ch1,ch2;
printf("put in a single float:");
scanf("%x",&input); //input is a unsigned long int
getchar(); //receive Enter
q=&input;
printf("q is %p\n",q);
p=(float*)q; //p is a single float pointer
printf("p is %p\n",p);
printf("*p is %x\n",*p);
printf("*q is %x\n",*q);
result=(long int)*p;
printf("***********************************\n");
printf("result is %x\n",result); //result is a single float
}