What is the difference between printf() and puts() in C?

前端 未结 10 2094
长发绾君心
长发绾君心 2020-12-07 07:27

I know you can print with printf() and puts(). I can also see that printf() allows you to interpolate variables and do formatting.

10条回答
  •  北海茫月
    2020-12-07 07:35

    puts is the simple choice and adds a new line in the end and printfwrites the output from a formatted string.

    See the documentation for puts and for printf.

    I would recommend to use only printf as this is more consistent than switching method, i.e if you are debbugging it is less painfull to search all printfs than puts and printf. Most times you want to output a variable in your printouts as well, so puts is mostly used in example code.

提交回复
热议问题