What is the difference between format specifier %i and %d? - ProProfs Discuss
Advertisement

What is the difference between format specifier %i and %d?

What is the difference between format specifier %i and %d?

Change Image    Delete

Asked by G. Horace, Last updated: Dec 17, 2024

+ Answer
Request
Question menu
Vote up Vote down

1 Answer

A. Daniels

A. Daniels

A. Daniels
A. Daniels, Professor, San Diego

Answered Aug 06, 2018

In C language, the format specifiers %i and %d have subtle differences. %i can specify integers with decimal, hexadecimal or octal type values, while %d specifies signed decimal integers with negative or positive values. When used with the output function Printf (for writing format), there is no difference between %i and %d.

However, when used with the Scanf (for reading input) %i automatically detects the base integer where %d assumes the integer base is base 10. So, to enter a value using %i in hexadecimal format, the value needs to be preceded using “0x” and in octal format, the value needs to be preceded by “0”.

upvote downvote
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

Email Sent
We have sent an email to your address "" with instructions to reset your password.