赞
踩
2021年2月1日 周一 天气晴 【不悲叹过去,不荒废现在,不惧怕未来】
printf(str): 由于printf
支持可变参数,所以后续变量的个数就需要通过str中的格式化串来确定。当str
串中包含%s,%d,%c
等格式化串时,printf
就会去栈中找这个格式化串对应的变量,但实际上,根本没有向printf
压入更多的参数,因此就会出现打印失败或者程序崩溃的现象,如下图所示:
因此,在写代码的时候,一定不要用printf(str)
,老老实实使用printf(str,%s)
。
参考文献
https://blog.csdn.net/readonlyfile/article/details/25222587?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-5.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-5.control
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。