Yes.
From 7.21.6.5 Function snprintf , N1570 (project C11):
The snprintf function is equivalent to fprintf, except that the output is written to an array (specified by s), not a stream. If n is zero, nothing is written and s may be a null pointer . Otherwise, output characters beyond n-1 are discarded rather than written to the array, and the null character is written at the end of the characters actually written to the array. If copying occurs between overlapping objects, the behavior is undefined.
This is a useful method for finding the length of unknown data, for which you can first find the desired length and then allocate the exact amount of memory. Typical use case:
char *p; int len = snprintf(0, 0, "%s %s some_long_string_here_", str1, str2); p = malloc(len + 1); snprintf(p, len + 1, "%s %s some_long_string_here", str1, str2);
source share