相关疑难解决方法(0)

printf()的字符串宽度是否安全,没有未终止的字符串?

以下是否定义明确?

const char not_a_c_string[] = { 'h', 'e', 'l', 'l', 'o' };
printf( "%.5s", (const char*) not_a_c_string );
Run Code Online (Sandbox Code Playgroud)

这是关于具体形式的问题"%.5s",而不是如何打印可能不是NUL终止的字符串?因为这个问题已在这里得到解答,其中"%.*s"提出了构造.

c printf undefined-behavior language-lawyer

4
推荐指数
1
解决办法
693
查看次数

标签 统计

c ×1

language-lawyer ×1

printf ×1

undefined-behavior ×1