繁体   English   中英

如果`char`转换为`int`,为什么``%c'`存在于`printf`中?

[英]Why does `“%c”` exist in `printf` if `char` is converted to `int`?

在C中,你有printf"%c""%f"格式标志 - 和scanf的函数。 这两个函数都使用可变长度参数... ,它总是将floats转换为doubleschars转换为ints

我的问题是,如果发生这种转换,为什么存在charfloat单独标志? 为什么不使用与intdouble相同的标志?

相关问题:
为什么scanf()需要“%lf”用于双打,当printf()只用“%f”时可以吗?

因为打印出来的方式不同。

printf("%d \n",100); //prints 100
printf("%c \n",100); //prints d - the ascii character represented by 100

因为floatdouble具有不同的机器表示或大小,以及调用约定:许多处理器都有专用于浮点的寄存器,可用于参数传递。

C标准要求将short参数转换为int并将float参数转换为double

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM