As others have noted, trailing f
indicates formatted output (or formatted input for functions in the scanf
family).
However, I will add that the difference matters because it is important that the caller knows that the string must have the format specifier semantics. For example, do not do this:
char* s = get_some_user_input(); printf(s); // WRONG. Instead use: printf("%s", s) or fputs(stdout, s)
If s
contains %
characters, printing it directly with printf
may cause it to access non-existent arguments, which will lead to undefined behavior (and this is the reason for some security vulnerabilities). Follow this naming convention if you ever define your own printf
variational functions.
source share