Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does %s and %d represent?

Status
Not open for further replies.

xchen123

Technical User
Jun 19, 2003
3
US
In C code, what does the %s and %d represent?

Ex:

printf("Here it is %d\n",var1);

printf("MSG=%s\n",buf);
 
hi;)

printf("Here it is %d\n",var1);
//%d here mean that var1 will be print as an int.

printf("MSG=%s\n",buf);
//%s here mean that Buf will be print as a char array.

ex)
var1 = 10;
printf("Here it is %d\n",var1);
//will print : Here it is 10
var1 = 'A';
//will print : Here it is 65

--------------------
%c, for char ('a')
%f, for float (5.55)
%d, for double (100000)
etc..




 
%f for both float and double, %d is for int and %s expects a string - a null-terminated sequence of characters.

Note:

'A' needn't have the integer value 65, since C doesn't require the ASCII character set.

Integer character constants (e.g, 'a') have type int in C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top