954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

illustration of %i specifier

By Gaiety on Oct 14th, 2009 3:08 pm

/*
difference between %i ad %d

%i reads the value and it recognizes the value as what base
it is when we read the value as 023 (base 8) it is 19 (base 10)
and 0xa(base 16) it is 10 in (base 10).
*/


OUTPUT:

/*
Enter a number:023
Out put:%d=19, %i=19,%x=17

Enter a number:0xa
Out put:%d=10, %i=10,%x=a
*/

int main()
{
        int num;
        printf("Enter a number:");
        scanf("%i",&num);
        printf("\nOut put:%%d=%d, %%i=%i,%%x=%x",num,num,num);
        return 0;
}

But note that %i used by scanf() is different than %i used by printf(). For printf(), %i and %d are the same thing.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You