A format string is a string that contains placeholders such as %s or %d where variables are inserted into the string at runtime. Given that the handling of format strings may vary across programming languages, using a language tag to specify which language the question is about is also recommended when using this tag.
A format string is an implementation of string interpolation where a string contains various placeholders, such as %d
or %s
, that are replaced by variables of the specified type, typically via library function. An example is the C printf()
function:
int x = 10;
float pi = 3.14159
const char *str = "world";
printf("Hello %s %d %f\n", str, x, pi); // Hello world 10 3.14159
They may also contain arguments such as to specify how many digits of a float
to print:
printf("%.2f\n", pi); // 3.14
This tag is useful for questions about the usage or behavior of format strings, such as finding the correct format specifier to print a certain type in a desired way.
Related Tags: