# %i and %d place holders.

Discussion in 'C' started by Player, Feb 5, 2009.

1. ### PlayerNew Member

Joined:
Aug 3, 2007
Messages:
37
Likes Received:
0
Trophy Points:
0
Hi Guys.

Another quick question for you. I have just come across the %i place holder but i don't understand the difference between %i and %d. The section in my book that lists all the place holders says there both int place holders. In the program i am looking at it don't explain why the %i is used instead of %d. It's the first time i have come across the %i place holder. Sorry if it's a dumb question but i need to know everything

2. ### asadullah.ansariTechCake

Joined:
Jan 9, 2008
Messages:
356
Likes Received:
14
Trophy Points:
0
Occupation:
Developer
Location:
NOIDA
% i attempts to take as integer.
%d attempts to take decimal integer.

3. ### asadullah.ansariTechCake

Joined:
Jan 9, 2008
Messages:
356
Likes Received:
14
Trophy Points:
0
Occupation:
Developer
Location:
NOIDA
This example makes you more understand...

Code:
```#include <stdio.h>

int main()
{
char InStr[] = "150 0125";
int val1=0, val2=0;

//******* Reading integer values*****///
sscanf(InStr, "%i %i ", &val1, &val2);
//****************************************

printf("The Decimal values are : %d %d\n", val1,val2);
val1=0;
val2=0;

//******* Reading Decimal integer values*****///
sscanf(InStr, "%d %d", &val1, &val2);
//****************************************

printf("The Decimal values are : %d %d\n", val1,val2);
return 0;
}```
Output::

asadulla ~/temp> gcc test1.cc
execution gcc-3.3.1
asadulla ~/temp> ./a.out
The Decimal values are : 150 85
The Decimal values are : 150 125

Last edited: Feb 6, 2009