Alex Rivera | Logout

How to printf "unsigned long" in C?

Asked 2010-07-09T04:46:47.273
477

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

Suppose unsigned_foo is an unsigned long, then I try:

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

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

Edit
Report

1 Answer

14

The format is %lu.

Please check about the various other datatypes and their usage in printf here

answered 2010-07-09T06:08:13.523

Your Answer