Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What's the difference between printf and printf ( )?


Asked by Leon Benson on Dec 09, 2021 FAQ



The essential difference between puts (mystr); and printf (mystr); is that in the latter the argument is interpreted as a formatting string.
One may also ask,
printf is a C function to print a formatted string to the standard output stream which is the computer screen. fprintf is a C function to print a formatted string to a file. Syntax. Formatted string and list of parameters are passed to printf function.
Also, the printf () function is used to print both strings and variables to the screen while the puts () function only permits you to print a string only to your screen. puts is the simple choice and adds a new line in the end and printf writes the output from a formatted string.
Next,
The difference between printf and print is the format argument. This is an expression whose value is taken as a string; it specifies how to output each of the other arguments. It is called the format string. References here and here
Keeping this in consideration,
echo always exits with a 0 status, and simply prints arguments followed by an end of line character on the standard output, while printf allows for definition of a formatting string and gives a non-zero exit status code upon failure. printf has more control over the output format.