printf("%x\n",(const uint8_t *)0x0D);
printf("%x\n",(const uint8_t)0x0D);
printf("%x\n",(uint8_t *)0x0D);
printf("%x\n",0x0D);
他们都给我D
。这里的 const
和 *
有何意义?
最佳答案
%x
格式说明符将参数指定为 unsigned int
类型。
就您而言,
printf("%x\n",(const uint8_t)0x0D);
printf("%x\n",0x0D);
参数将被提升(默认提升规则)以匹配类型,但在这种情况下
printf("%x\n",(const uint8_t *)0x0D); //supplying a pointer
printf("%x\n",(uint8_t *)0x0D); //supplying a pointer
您将调用undefined behavior ,按照 C11
第 §7.21.6.1 章
[...] If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined. [...]
关于c - 请解释下面 printfs 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36909273/