วันจันทร์ที่ 20 กรกฎาคม พ.ศ. 2552

printf format reference

จดไว้กันลืม

d, i Print an int as a signed decimal number. '%d' and '%i' are synonymous for output, but are different when used with scanf() for input.
u Print decimal unsigned int. (short) // can print unsigned char as well
f, F Print a double in normal (fixed-point) notation. 'f' and 'F' only differs in how the strings for an infinite number or NaN are printed ('inf', 'infinity' and 'nan' for 'f', 'INF', 'INFINITY' and 'NAN' for 'F').
e, E Print a double value in standard form ([-]d.ddd e[+/-]ddd).An E conversion uses the letter E (rather than e) to introduce the exponent. The exponent always contains at least two digits; if the value is zero, the exponent is 00.
g, G Print a double in either normal or exponential notation, whichever is more appropriate for its magnitude. 'g' uses lower-case letters, 'G' uses upper-case letters. This type differs slightly from fixed-point notation in that insignificant zeroes to the right of the decimal point are not included. Also, the decimal point is not included on whole numbers.
x, X Print an unsigned int as a hexadecimal number. 'x' uses lower-case letters and 'X' uses upper-case.
o Print an unsigned int in octal.
s Print a character string.
c Print a char (character).
p Print a void * (pointer to void) in an implementation-defined format.


NameDescriptionSize*Range*
charCharacter or small integer.1bytesigned: -128 to 127
unsigned: 0 to 255
short int
(short)
Short Integer.2bytessigned: -32768 to 32767
unsigned: 0 to 65535
intInteger.4bytessigned: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int
(long)
Long integer.4bytessigned: -2147483648 to 2147483647
unsigned: 0 to 4294967295
boolBoolean value. It can take one of two values: true or false.1bytetrue or false
floatFloating point number.4bytes+/- 3.4e +/- 38 (~7 digits)
doubleDouble precision floating point number.8bytes+/- 1.7e +/- 308 (~15 digits)
long doubleLong double precision floating point number.8bytes+/- 1.7e +/- 308 (~15 digits)
wchar_tWide character.2 or 4 bytes1 wide character



ref : wiki, cplusplus

ไม่มีความคิดเห็น:

LinkWithin

Related Posts Plugin for WordPress, Blogger...