Thursday, 22 October 2015

Difference between format specifiers %i and %d in printf?

They are the same when used for output, e.g. with printf.

 But different when used as input specifier e.g. with scanf, where %d scans an integer as a signed decimal number, but %i defaults to decimal but also allows hexadecimal (if preceded by "0x") and octal if preceded by "0".

So "033" would be 27 with %i but 33 with %d.

No comments:

Post a Comment