confusion about short data type format specifier in C

给你一囗甜甜゛ 提交于 2019-12-05 22:54:30
printf("%hi\n", a);

a is promoted to int as per the rules of default argument promotion of variadic functions.

Anyway as you use h specifier the implementation is allowed to expect the int value is within SHRT_MIN or SHRT_MAX limits. Passing a value outside the bounds is undefined behavior.

Of course printf("%i\n", a); is also valid because of the int promotion of a so using %hi conversion specification is not very usual.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!