Why do I have to specify data type each time in C?

后端 未结 11 2723
温柔的废话
温柔的废话 2020-12-12 18:17

As you can see from the code snippet below, I have declared one char variable and one int variable. When the code gets compiled, it must identify t

11条回答
  •  抹茶落季
    2020-12-12 18:24

    The first parameter is a format string. If you're printing a decimal number, it may look like:

    • "%d" (decimal number)
    • "%5d" (decimal number padded to width 5 with spaces)
    • "%05d" (decimal number padded to width 5 with zeros)
    • "%+d" (decimal number, always with a sign)
    • "Value: %d\n" (some content before/after the number)

    etc, see for example Format placeholders on Wikipedia to have an idea what format strings can contain.

    Also there can be more than one parameter here:

    "%s - %d" (a string, then some content, then a number)

提交回复
热议问题