Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What is the argument for printf that formats a long?

The printf function takes an argument type, for example, %d or %i for a marked int. In any case, I don't see anything for a long worth.
by

4 Answers

rahul07
Put an l (lowercased letter L) directly before the specifier.

unsigned long n;
long m;

printf("%lu %ld", n, m);
RoliMishra
It depends, if you are referring to unsigned long the formatting character is "%lu". If you're referring to signed long the formatting character is "%ld".
sandhya6gczb
On most platforms, long and int are the same size (32 bits). Still, it does have its own format specifier:

long n;
unsigned long un;
printf("%ld", n); // signed
printf("%lu", un); // unsigned

For 64 bits, you'd want a long long:

long long n;
unsigned long long un;
printf("%lld", n); // signed
printf("%llu", un); // unsigned

Oh, and of course, it's different in Windows:

printf("%l64d", n); // signed
printf("%l64u", un); // unsigned
kshitijrana14
In case you're looking to print unsigned long long as I was, use:
unsigned long long n;
printf("%llu", n);

Login / Signup to Answer the Question.