printf长度修饰符 [英] printf length modifier
本文介绍了printf长度修饰符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
以下代码是否会调用未定义的行为?
#include< stdio.h>
int main(无效)
{
unsigned short int u = 42;
printf("%u \ n" ,u);
返回0;
}
gcc似乎并不介意。
$ gcc -Wall -Wextra -std = c89 -pedantic zzz.c
$ ./a.out
是否必须在格式字符串中添加h长度修饰符?
unsigned short int u = 42;
printf( "%hu \ n",u);
问候。
Hello,
Does the following code invoke undefined behavior?
#include <stdio.h>
int main(void)
{
unsigned short int u = 42;
printf("%u\n", u);
return 0;
}
gcc doesn''t seem to mind.
$ gcc -Wall -Wextra -std=c89 -pedantic zzz.c
$ ./a.out
42
Is it mandatory to add the ''h'' length modifier in the format string?
unsigned short int u = 42;
printf("%hu\n", u);
Regards.
推荐答案
gcc -Wall -Wextra -std = c89 -pedantic zzz.c
gcc -Wall -Wextra -std=c89 -pedantic zzz.c
./ a.out
是否必须在格式字符串中添加''h''长度修饰符?
unsigned short int u = 42;
printf(" ;%hu \ n",u);
Rega rds。
./a.out
42
Is it mandatory to add the ''h'' length modifier in the format string?
unsigned short int u = 42;
printf("%hu\n", u);
Regards.
Spoon写道:
Spoon wrote:
>
请执行以下代码调用未定义的行为?
#include< stdio.h>
int main(无效)
{
unsigned short int u = 42;
printf("%u\\\
",u);
返回0;
}
>
Does the following code invoke undefined behavior?
#include <stdio.h>
int main(void)
{
unsigned short int u = 42;
printf("%u\n", u);
return 0;
}
是。
Yes.
>
gcc doesn'好像在想。
>
gcc doesn''t seem to mind.
这篇关于printf长度修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文