How to printf “unsigned long” in C?

后端 未结 7 596
有刺的猬
有刺的猬 2020-11-28 01:08

I can never understand how to print unsigned long datatype in C.

Suppose unsigned_foo is an unsigned long, then I try:

7条回答
  •  半阙折子戏
    2020-11-28 01:16

    Out of all the combinations you tried, %ld and %lu are the only ones which are valid printf format specifiers at all. %lu (long unsigned decimal), %lx or %lX (long hex with lowercase or uppercase letters), and %lo (long octal) are the only valid format specifiers for a variable of type unsigned long (of course you can add field width, precision, etc modifiers between the % and the l).

提交回复
热议问题