in C programming we can use both %d and %i for interger variable.
that is, both these give same output:
printf(" %d", x);
printf(" %i" , x);
whats the difference between %d and %i ??
C programming?
Basics:
NO! %d %26amp; %i are not same. But they sure have similar functionality.
They are similar because, they are used to handle signed integer values.
But they are DIFFERENT because;while %d interprets the argument as decimal integer. %i handles decimal, octal or hexadecimal integer values.
Details:
Syntax of printf : int printf("%26lt;control string%26gt;", arg1,arg2....);
Control strings(also called format strings) contain specifications which direct the interpretation of input(in case of scanf)/output data.
When using decimal integers use %d.
Use %i when any one/all of decimal,octal, hexadecimal integers are to handled.Here '%' is the conversion character
Here area few others, which would help in further understanding the difference
%i=for decimal,octal or hexadecimal
%d=for decimal
%x=for hexadecimal
%o=for octal
I restrict myself only to the direct-n-concise answer to your question,yet dont restrict yourself to this only. There are a lot more fexibility provided by these functions.
Reply:None, really. They are both signed decimal integers.
Reply:I don't think there's any difference. But %d is explicitely decimal, so use it if you want to make clear that it's a decimal number.
primrose
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment