Passing too many arguments to printf

前端 未结 5 992
不思量自难忘°
不思量自难忘° 2020-11-30 10:56

Any C programmer who\'s been working for more than a week has encountered crashes that result from calling printf with more format specifiers than actual argume

5条回答
  •  佛祖请我去吃肉
    2020-11-30 11:16

    printf is designed to accept any number of arguments. printf then reads the format specifier (first argument), and pulls arguments from the argument list as needed. This is why too few arguments crash: the code simply starts using non-existent arguments, accessing memory that doesn't exist, or some other bad thing. But with too many arguments, the extra arguments will simply be ignored. The format specifier will use fewer arguments than have been passed in.

提交回复
热议问题