The printf
function takes an argument type, such as %d or %i for a signed int. However, I don't see anything for a long value.
views:
6727answers:
5
A:
[edit: this is incorrect... see other answers regarding %ld]
I'm pretty sure that %d or %i just signify to treat the input as an integer regardless of its size. So whether it is 8, 16, 32, or 64 bits it will be printed as an integer.
As an aside, on x86 Windows and I believe w/ GCC, ints and longs are actually both 32 bits.
Ben Childs
2008-09-01 22:47:16
+13
A:
Put an 'l' directly before the specifier.
unsigned long n;
printf("%ld", n);
postfuturist
2008-09-01 22:50:23
+4
A:
@steveth45: I think you mean:
unsigned long n;
printf("%lu", n); // unsigned long
or
long n;
printf("%ld", n); // signed long
Am I right?
Blorgbeard
2008-09-01 23:26:02
+1
A:
I think to answer this question definitively would require knowing the compiler name and version that you are using and the platform (CPU type, OS etc.) that it is compiling for.
Andrew O'Reilly
2008-09-02 19:20:35