The type of an unsuffixed integer literal such as 4294967296
depends on the value of the literal and the ranges of the predefined types for the implementation.
The type of a decimal constant is the first of:
int
long int
long long int
(Octal and hexadecimal literals can be of unsigned types; see section 6.4.4.1 of the C99 standard for details.)
in which its value can be represented exactly. The language requires that int
is at least 16 bits, long int
is at least 32 bits, and long long int
is at least 64 bits, but each can be wider.
On your system (Ubuntu, 32 bits, same as mine), int
and long int
are both 32 bits, and long long int
is 64 bits, so 4294967296
is of type long long int
. (The message you showed us indicates that it's long long unsigned int
, which doesn't seem right; are you sure that's the message you got for that specific code?)
The behavior of calling printf
with an argument of a type that's inconsistent with the format is undefined. You probably got 9
as output because the value passed was 0x0000000100000000
, and printf
happened to use the low-order 32 bits of the 64-bit value. Other behaviors are possible.
You ask for "Any suggestion", but it's not clear from your question what you want to do. A way to produce the output you probably expected is:
puts("4294967296");
but I'm sure that's not the kind of answer you're looking for.
Usually when you print a number with printf
, the argument will be a variable rather than a literal, and the type will be determined by the declared type of the variable. Or it might be a more complicated expression, in which case the type is determined by the types of the operands; if they're of different types, there's a moderately complicated set of rules that determine what the final result is. Just make sure the format you use corresponds to the (promoted) type of the argument.
If you have a more specific question, we'll be glad to give a more specific answer.