Consider printf("element %zu is %g,\tits square is %g\n", i, A[i], A[i]*A[i]);. The quoted character sequence combines ordinary output, escape characters, and conversion directives. Each directive beginning with % marks where a later argument supplies formatted output. section 1.1
A format specification can contain flags, width, precision, modifiers, and a required specifier: %[FF][WW][.PP][LL]SS. The specifier selects the conversion, while the modifier identifies the corresponding argument type. The number of arguments must exactly match the % specifiers; otherwise behavior is undefined. section 8.3.4
Choose a directive according to the value’s meaning:
- Use %d or %u for decimal signed or unsigned integers, %x for unsigned bit patterns, and %g for generic floating-point output. section 8.3.4
- Use %s for strings, %c for characters, %p for addresses, and %% for a literal percent character. section 11.1.3
- Match type-sensitive modifiers such as z for size_t, t for ptrdiff_t, and L for long double; mismatches can cause problems. section 8.3.4
Formatted input uses the same idea differently
scanf(" %lg %lg %lg ", &a[0], &a[1], &a[2]) reads three double values through pointer arguments. In input formats, whitespace matches any sequence of whitespace, and %s consumes non-whitespace characters while adding a terminating 0. These conventions differ subtly from printf, so scanf formats require extra care. section 14.2
17 printf("element %zu is %g, \tits square is %g\n",
18 i,
19 A[i],
20 A[i]*A[i]);
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":2}],[{\"line\":0,\"ch\":6},{\"line\":0,\"ch\":12}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":2}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":2}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":2}]]"}
!@%STYLE%@!
Inspect the complete printf call alongside its format directives and supplied expressions. section 1.1




