Skip to content

C:printf

c printf method.

printf unsigned long long int type

Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU).

printf("%llu", 285212672);

printf std::size_t type

std::size_t size = 1234;
printf("%zu", size);

Printf Tricks

It may be old-fashioned, but I still find printf (and sprintf and _vsnprintf) incredibly useful, both for printing debug output and for generating formatted strings. Here are a few lesser-known formats that I use again and again. See MSDN for the full reference.

  • %04x - 4-digit hex number with leading zeroes
  • %p - pointer
  • %I64d, %I64u, %I64x - 64-bit integers
  • %Iu, %Id, %Ix - ULONG_PTR
  • %*d - runtime width specifier
  • %.*s - print a substring
  • %.0d - print nothing for zero
  • %#x - print a leading 0x

C++ format

See also

Favorite site

References


  1. Weblogs.asp.net_-_printf_tricks.pdf