且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何给printf"无符号长"用C?

更新时间:2022-10-19 11:27:55

%禄格式正确无符号长。听起来有在起作用等问题在这里,如内存损坏或者未初始化的变量。也许我们展示一个较大的画面?

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

Suppose unsigned_boo is an unsigned long, then I try:

  • printf("%lu\n", unsigned_boo)
  • printf("%du\n", unsigned_boo)
  • printf("%ud\n", unsigned_boo)
  • printf("%ll\n", unsigned_boo)
  • printf("%ld\n", unsigned_boo)
  • printf("%dl\n", unsigned_boo)

And all of them print some kind of -123123123 number instead of unsigned long that I have.

%lu is the correct format for unsigned long. Sounds like there are other issues at play here, such as memory corruption or an uninitialized variable. Perhaps show us a larger picture?