简体   繁体   English

printf 中的“%.#s”是什么意思?

[英]What does “%.#s” mean in printf?

I have got a question in hackerearth to check if there is an error in this printf statement.Can you tell me if there is any meaning for this line below?我在hackerearth有一个问题要检查这个printf语句是否有错误。你能告诉我下面这行是否有任何意义吗? Here这里

str="qwertyABC"

printf("%.#s",str)

This statement will invoke undefined behavior because format specification is invalid since # is not defined as a conversion specifier.此语句将调用未定义的行为,因为格式规范无效,因为#未定义为转换说明符。

To use # as a flag, it must be placed before .要将#用作标志,它必须放在 之前. , which specifies the precision. ,它指定精度。

Moreover, using # as a flag, like printf("%#.s",str) will also invoke undefined behavior because the # ("alternative form") flag is not defined for the %s conversion specifier.此外,使用#作为标志,例如printf("%#.s",str)也会调用未定义的行为,因为没有为%s转换说明符定义# (“替代形式”)标志。

There are two errors in your printf statement:您的printf语句中有两个错误:

  1. The # is not a valid field width or precision specifier. #不是有效的字段宽度或精度说明符。
  2. The statement is missing a terminating semicolon.该语句缺少终止分号。

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

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