廣告贊助

 

函式原型:  int printf ( const char * format, ... ); 

引數說明: %[flags][width][.precision][length]specifier
                %[旗標][寬度][.精度][長度修飾]資料型態

 

1. 資料型態 %[旗標][寬度][.精度][長度修飾]資料型態 ) 必填欄位 

(1.1) 字元/字串

   %c, %C : 字元,  char c;
       %s : 字元陣列, char buffer[MAX_PATH];
       %S : 字元陣列(Unicode), wchar buffer[MAX_PATH];

[] %C / %S 並未被收在標準函式庫裡,屬 MSVC 特殊支援。

(1.2) 整數


    %d, %i : 10進制整數  , int x; [lemma] 
        %u : 10進制無號數, unsigned int x;
        %o : 8進制無號數,  unsigned int x;
     %x, %X : 16進制無號數小寫x輸出為"abcdef", 大寫 X 輸出為 "ABCDEF", 
              unsigned x;
%lld, %I64d : long long int, __int64 
輸出型態
             (註:vc6.0 下只有 __int64,沒有long long int)
%llu, %I64u : unsigned long long int  輸出型態

[lemma] %d : dec; %i : integer,於 scanf 時有部份差異 (%d 只接受10進位, %i 可接受指定進位,如 0x23, 045),但於 printf  %d, %i 並無顯著差異 (感謝 Jacob Lee 補充指導)

 

(1.3) 浮點數

   %e, %E : 浮點數使用科學符號表示之,指數將帶正負號, float x,doubley;
       %f : 單精度浮點數(預設輸出精度6), float x;
            ( :  printf 而言, %f/%lf 可適用於 double / float)
      %lf : 倍精度浮點數(預設輸出精度6), double x;
%llf, %LF : 雙倍精度浮點數(預設輸出精度6), long double x;
   %g, %G : 由系統決定是否採科學符號表示。

(1.4) 特殊 原創:edisonx.pixnet.net

       %p : 變數位置。 ex:
            int a=0, printf("%p", &a);   printf("%08x", &a);
       %n : 輸出至緩衝區之長度, ex:
            char str[]="test", int len, printf("%s%n", a, &len);
            
輸出4bytes,len = 4

(1.5) C99新增 < 建議 k spec. 最清楚 >

( : C99 新增了一些資料型態在 inttypes.h / stdint.h 裡面,有興趣搜尋 n1256.pdf 下載下來 K 標準, in section 7.8 。當然 MSVC 不支援 C99 是眾所皆知的事。)

部份原則還是掌握了 %i, %u, %d, %x,另由於這部份在 printf 會顯得很亂,故直接做範例對應。掌握一原則:新的資料型態在 printf 前三個字母一定是 PRI

   "%" PRIdN , "%" PRIiN以十進位有號數顯示 intN_t 系列之數值。ex : 

         int8_t i8  = 8  ; <----> printf( "i8 = %" PRId8  " \n", i8);
         int8_t i16 = 16 ; <----> printf( "i16= %" PRIi16 " \n", i16);
         int8_t i32 = 32 ; <----> printf( "i32= %" PRId32 " \n", i32); 
         int8_t i64 = 64 ; <----> printf( "i64= %" PRIi64 " \n", i64); 

 

另上述將 PRIdN / PRIiN ,換成 PRIoN / PRIuN / PRIxN / PRIX,便可轉對 uintN_t 資料型態做輸出,分別為 ( 8 進位、10進位、16進位小寫、16進位大寫),有空自己試試,不贅述。 

 

   "%" PRIdLEASTN , "%" PRIiLEASTN以十進位有號數顯示 int_leastN_t 系列之數值。ex : 

         int_least8_t  i8  = 8  ; <----> printf( "i8 = %" PRIdLEAST8  " \n", i8);
         int_least16_t i16 = 16 ; <----> printf( "i16= %" PRIiLEAST16 " \n", i16);
         int_least32_t i32 = 32 ; <----> printf( "i32= %" PRIdLEAST32 " \n", i32); 
         int_least64_t i64 = 64 ; <----> printf( "i64= %" PRIiLEAST64 " \n", i64); 

 

 另上述將 PRIdLEAST/ PRIiLEAST 換成 PRIoLEASTN/ PRIuLEASTN/ PRIxLEASTN/ PRIXLEASTN 便可轉對 uint_leastN_t 資料型態做輸出,分別為 ( 8 進位、10進位、16進位小寫、16進位大寫),有空自己試試,不贅述。 

 

    "%" PRIdFASTN , "%" PRIiFASTN以十進位有號數顯示 int_fastN_t 系列之數值。ex : 

         int_fast8_t  i8  = 8  ; <----> printf( "i8 = %" PRIdFAST8  " \n", i8);
         int_fast16_t i16 = 16 ; <----> printf( "i16= %" PRIiFAST16 " \n", i16);
         int_fast32_t i32 = 32 ; <----> printf( "i32= %" PRIdFAST32 " \n", i32); 
         int_fast64_t i64 = 64 ; <----> printf( "i64= %" PRIiFAST64 " \n", i64); 

 

 另上述將 PRIdFAST/ PRIiFAST,換成 PRIoFASTN/ PRIuFASTN/ PRIxFASTN/ PRIXFASTN,便可轉對 uint_leastN_t 資料型態做輸出,分別為 ( 8 進位、10進位、16進位小寫、16進位大寫),有空自己試試,不贅述。 

 

   "%" PRIdMAX , "%" PRIdPTR : 分別顯示整數最大值與指標型態。

 

[ : 特別注意 inttypes.h 裡面之型態,printf 引數和 scanf 引數差很多,一樣掌握一原則,新的資料型態在 scan前三個字母一定是 SCN 如 intN_t  系列,scanf 用的是 "%" SCNdN / "%" SCNi uintN_t 系列,scanf 用的是 "%" SCNoN / "%" SCNu/ "%" SCNxN / "%" SCNX int_fastN_t / int_leastN_t 等系列資料型態便不贅述。 )

 

2. 寬度 %[旗標][寬度][.精度][長度修飾]資料型態 ) 選填欄位net

      %m : 指定輸出之寬度。ex:
           int a=2, b=10;
           printf("%d%5d", a, b);
           
輸出為   "2   10"  (210之間有3個空白,因105個文字寬度)
      %* : 以引數方式代入指定輸出之寬度。ex:
           int a=2, width=10;
           printf("%*d",width, a);
           
輸出為   "         2"  (10個文字寬度)

3. 長度修飾 ( %[旗標][寬度][.精度][長度修飾]資料型態 ) 選填欄位

 

      %h : 將數字視為 short int (%hd)  unsigned int (%hu),
           此修飾只對整數型態之 %hi, %hd, %ho, %hu, %hx, %hX 有效。
           且針對 char 可用 %hhdunsigned char 可用 %hhu

     ( : MSVC 認得 %hd / %hu / %hhd / %hhu , 但在 gcc 下會發出認不得的警告 )

      %l : 將數字視為 long  int (%ld)  unsigned long int (%lu), 
           此修飾只對整數型態之 %li, %ld, %lo, %lu, %lx, %lX 有效。
      %L : 此修飾只對浮點數型態之 long double 有效可用於修飾
           %Le, %LE, %Lf, %Lg, %LG

4. 精度 ( %[旗標][寬度][.精度][長度修飾]資料型態 ) 選填欄位 

     %.n : 欲輸出小數點後幾位數,即顯示之精度,此修飾只對浮點數資料型態有效(f,F,e,E,g),
           若使用其它整數型態 (i, d, o, u, x, X) 則將 n 視為 0, 即不輸出小數位數。ex:
           double a=2.1234, printf("%.2lf", a);
           
輸出則為  "2.12" 
     %.* :  %.n 相似,但其 n 值可用變數引入。ex:
           double a=1.3456, int preci=2, printf("%.*lf",preci, a);
           
輸出則為  "1.35" 
     %m.n: 這是寬度和精度合用之方法代表輸出會有小數點後 n 位,
           且整個輸出文字寬 m 個字(包含小數點、正負號及數字)ex:
           double c = -102.34567, printf("%10.3lf", c);
           
結果會輸出  "  -102.346" ,前面將會保留二個空白,使得整體寬度為 10 
     %*.*: 和上一說明一樣但寬度與精度可用引數決定。ex:
           double c = -102.34567, int m=10, int n=3;
           printf("%*.*lf", m, n, c);
           
結果會輸出  "  -102.346" ,前面將會保留二個空白,使得整體寬度為 10 

5. 旗標 ( %[旗標][寬度][.精度][長度修飾]資料型態 ) 選填欄位 

       %- : 原本輸出預設為向右對齊,使用後輸出向左對齊需與[寬度]配合使用。ex:
            char buf[] = "Test";
            printf("%-10s");
            
輸出結果為 "Test      " Test 後面將保留6個空白。             
       %+ : 需為數值型之資料型態,強制輸出正負號,可與 '-' 旗標合用。 ex:
            double a = 3.4567:
            printf("%-+8.2lf", a);
            // '-'
使輸出靠左對齊, '+'強調輸出正負號整體寬度為8, 小數點顯示2位。
            輸出結果為 "+3.46   "
       %0 : 若輸出之左半部為空白處則進行補0, (所以這不能和 '-' 合用) ex:
            unsigned int x = 122;
            printf("%05u", x); 
            // 
寬度為5, 前半空白補零
            輸出結果為 "00122"
       %# : 對進制加上前綴符號只對 %o, %x 有用
            %#o8進制,前綴符號為 0,
            %#x16進制,前綴符號為 0x, %#X前綴符號則為 0Xex:
            unsigned int a = 15;
            printf("%u %#o %#X", a, a, a);
            
輸出結果為 "15 017 0XF" 
   %(空白): 若數字為正號則會在該數字前面加上一空白,(故不可與 '+' 合用) ex:
            int a=10;
            printf("% -5d"); // 
寬度5, 向左對齊保留正號位置
            輸出結果為 " 10  "

 

Print formatted data to stdout

 

specifier

Output

Example

d or i

Signed decimal integer

392

u

Unsigned decimal integer

7235

o

Unsigned octal

610

x

Unsigned hexadecimal integer

7fa

X

Unsigned hexadecimal integer (uppercase)

7FA

f

Decimal floating point, lowercase

392.65

F

Decimal floating point, uppercase

392.65

e

Scientific notation (mantissa/exponent), lowercase

3.9265e+2

E

Scientific notation (mantissa/exponent), uppercase

3.9265E+2

g

Use the shortest representation: %e or %f

392.65

G

Use the shortest representation: %E or %F

392.65

a

Hexadecimal floating point, lowercase

-0xc.90fep-2

A

Hexadecimal floating point, uppercase

-0XC.90FEP-2

c

Character

a

s

String of characters

sample

p

Pointer address

b8000000

n

Nothing printed.
The corresponding argument must be a pointer to a 
signed int.
The number of characters written so far is stored in the pointed location.

 

%

% followed by another % character will write a single % to the stream.

%



 
specifiers
length d i u o x X f F e E g G a A c s p n
(none) int unsigned int double int char* void* int*
hh signed char unsigned char         signed char*
h short int unsigned short int         short int*
l long int unsigned long int   wint_t wchar_t*   long int*
ll long long int unsigned long long int         long long int*
j intmax_t uintmax_t         intmax_t*
z size_t size_t         size_t*
t ptrdiff_t ptrdiff_t         ptrdiff_t*
L     long double        
 

Data Type Ranges

類型名稱

位元組

其他名稱

值的範圍

printf format

scanf format

int

4

signed

2,147,483,648  2,147,483,647

%d

 

unsigned int

4

unsigned

 4,294,967,295

%u

 

__int8

1

char

128  127

%d

%hhd

unsigned __int8

1

unsigned char

 255

   

__int16

2

shortshort intsigned short int

32,768  32,767

   

unsigned __int16

2

unsigned shortunsigned short int

 65,535

 

%hu

__int32

4

signedsigned intint

2,147,483,648  2,147,483,647

   

unsigned __int32

4

unsignedunsigned int

 4,294,967,295

   

__int64

8

long longsigned long long

9,223,372,036,854,775,808 9,223,372,036,854,775,807

%I64d

 

unsigned __int64

8

unsigned long long

 18,446,744,073,709,551,615

   

bool

1

false  true

   

char

1

預設為 –128  127

   

signed char

1

128  127

   

unsigned char

1

 255

   

short

2

short intsigned short int

32,768  32,767

   

unsigned short

2

unsigned short int

 65,535

 

%hu

long

4

long intsigned long int

2,147,483,648  2,147,483,647

   

unsigned long

4

unsigned long int

 4,294,967,295

   

long long

8

 (但是相當於 __int64)

9,223,372,036,854,775,808 9,223,372,036,854,775,807

   

unsigned long long

8

 (但是相當於 unsigned __int64)

 18,446,744,073,709,551,615

   

enum

視情況而定

請參閱本文件稍後的備註

   

浮動

4

3.4E +/- 38 (7 位數)

   

double

8

1.7E +/- 308 (15 位數)

   

長雙精度

 double 相同

 double 相同

   

wchar_t

2

__wchar_t

 65,535

   
 

Windows Data Types

Data type Description
APIENTRY

The calling convention for system functions.

This type is declared in WinDef.h as follows:

#define APIENTRY WINAPI

ATOM

An atom. For more information, see About Atom Tables.

This type is declared in WinDef.h as follows:

typedef WORD ATOM;

BOOL

A Boolean variable (should be TRUE or FALSE).

This type is declared in WinDef.h as follows:

typedef int BOOL;

BOOLEAN

A Boolean variable (should be TRUE or FALSE).

This type is declared in WinNT.h as follows:

typedef BYTE BOOLEAN;

BYTE

A byte (8 bits).

This type is declared in WinDef.h as follows:

typedef unsigned char BYTE;

CALLBACK

The calling convention for callback functions.

This type is declared in WinDef.h as follows:

#define CALLBACK __stdcall

CALLBACK, WINAPI, and APIENTRY are all used to define functions with the __stdcall calling convention. Most functions in the Windows API are declared using WINAPI. You may wish to use CALLBACK for the callback functions that you implement to help identify the function as a callback function.

CCHAR

An 8-bit Windows (ANSI) character.

This type is declared in WinNT.h as follows:

typedef char CCHAR;

CHAR

An 8-bit Windows (ANSI) character. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef char CHAR;

COLORREF

The red, green, blue (RGB) color value (32 bits). See COLORREF for information on this type.

This type is declared in WinDef.h as follows:

typedef DWORD COLORREF;

CONST

A variable whose value is to remain constant during execution.

This type is declared in WinDef.h as follows:

#define CONST const

DWORD

A 32-bit unsigned integer. The range is 0 through 4294967295 decimal.

This type is declared in IntSafe.h as follows:

typedef unsigned long DWORD;

DWORDLONG

A 64-bit unsigned integer. The range is 0 through 18446744073709551615 decimal.

This type is declared in IntSafe.h as follows:

typedef unsigned __int64 DWORDLONG;

DWORD_PTR

An unsigned long type for pointer precision. Use when casting a pointer to a long type to perform pointer arithmetic. (Also commonly used for general 32-bit parameters that have been extended to 64 bits in 64-bit Windows.)

This type is declared in BaseTsd.h as follows:

typedef ULONG_PTR DWORD_PTR;

DWORD32

A 32-bit unsigned integer.

This type is declared in BaseTsd.h as follows:

typedef unsigned int DWORD32;

DWORD64

A 64-bit unsigned integer.

This type is declared in BaseTsd.h as follows:

typedef unsigned __int64 DWORD64;

FLOAT

A floating-point variable.

This type is declared in WinDef.h as follows:

typedef float FLOAT;

HACCEL

A handle to an accelerator table.

This type is declared in WinDef.h as follows:

typedef HANDLE HACCEL;

HALF_PTR

Half the size of a pointer. Use within a structure that contains a pointer and two small fields.

This type is declared in BaseTsd.h as follows:

 
#ifdef _WIN64
 typedef int HALF_PTR;
#else
 typedef short HALF_PTR;
#endif

HANDLE

A handle to an object.

This type is declared in WinNT.h as follows:

typedef PVOID HANDLE;

HBITMAP

A handle to a bitmap.

This type is declared in WinDef.h as follows:

typedef HANDLE HBITMAP;

HBRUSH

A handle to a brush.

This type is declared in WinDef.h as follows:

typedef HANDLE HBRUSH;

HCOLORSPACE

A handle to a color space.

This type is declared in WinDef.h as follows:

typedef HANDLE HCOLORSPACE;

HCONV

A handle to a dynamic data exchange (DDE) conversation.

This type is declared in Ddeml.h as follows:

typedef HANDLE HCONV;

HCONVLIST

A handle to a DDE conversation list.

This type is declared in Ddeml.h as follows:

typedef HANDLE HCONVLIST;

HCURSOR

A handle to a cursor.

This type is declared in WinDef.h as follows:

typedef HICON HCURSOR;

HDC

A handle to a device context (DC).

This type is declared in WinDef.h as follows:

typedef HANDLE HDC;

HDDEDATA

A handle to DDE data.

This type is declared in Ddeml.h as follows:

typedef HANDLE HDDEDATA;

HDESK

A handle to a desktop.

This type is declared in WinDef.h as follows:

typedef HANDLE HDESK;

HDROP

A handle to an internal drop structure.

This type is declared in ShellApi.h as follows:

typedef HANDLE HDROP;

HDWP

A handle to a deferred window position structure.

This type is declared in WinUser.h as follows:

typedef HANDLE HDWP;

HENHMETAFILE

A handle to an enhanced metafile.

This type is declared in WinDef.h as follows:

typedef HANDLE HENHMETAFILE;

HFILE

A handle to a file opened by OpenFile, not CreateFile.

This type is declared in WinDef.h as follows:

typedef int HFILE;

HFONT

A handle to a font.

This type is declared in WinDef.h as follows:

typedef HANDLE HFONT;

HGDIOBJ

A handle to a GDI object.

This type is declared in WinDef.h as follows:

typedef HANDLE HGDIOBJ;

HGLOBAL

A handle to a global memory block.

This type is declared in WinDef.h as follows:

typedef HANDLE HGLOBAL;

HHOOK

A handle to a hook.

This type is declared in WinDef.h as follows:

typedef HANDLE HHOOK;

HICON

A handle to an icon.

This type is declared in WinDef.h as follows:

typedef HANDLE HICON;

HINSTANCE

A handle to an instance. This is the base address of the module in memory.

HMODULE and HINSTANCE are the same today, but represented different things in 16-bit Windows.

This type is declared in WinDef.h as follows:

typedef HANDLE HINSTANCE;

HKEY

A handle to a registry key.

This type is declared in WinDef.h as follows:

typedef HANDLE HKEY;

HKL

An input locale identifier.

This type is declared in WinDef.h as follows:

typedef HANDLE HKL;

HLOCAL

A handle to a local memory block.

This type is declared in WinDef.h as follows:

typedef HANDLE HLOCAL;

HMENU

A handle to a menu.

This type is declared in WinDef.h as follows:

typedef HANDLE HMENU;

HMETAFILE

A handle to a metafile.

This type is declared in WinDef.h as follows:

typedef HANDLE HMETAFILE;

HMODULE

A handle to a module. The is the base address of the module in memory.

HMODULE and HINSTANCE are the same in current versions of Windows, but represented different things in 16-bit Windows.

This type is declared in WinDef.h as follows:

typedef HINSTANCE HMODULE;

HMONITOR

A handle to a display monitor.

This type is declared in WinDef.h as follows:

if(WINVER >= 0x0500) typedef HANDLE HMONITOR;

HPALETTE

A handle to a palette.

This type is declared in WinDef.h as follows:

typedef HANDLE HPALETTE;

HPEN

A handle to a pen.

This type is declared in WinDef.h as follows:

typedef HANDLE HPEN;

HRESULT

The return codes used by COM interfaces. For more information, see Structure of the COM Error Codes. To test an HRESULT value, use the FAILED and SUCCEEDED macros.

This type is declared in WinNT.h as follows:

typedef LONG HRESULT;

HRGN

A handle to a region.

This type is declared in WinDef.h as follows:

typedef HANDLE HRGN;

HRSRC

A handle to a resource.

This type is declared in WinDef.h as follows:

typedef HANDLE HRSRC;

HSZ

A handle to a DDE string.

This type is declared in Ddeml.h as follows:

typedef HANDLE HSZ;

HWINSTA

A handle to a window station.

This type is declared in WinDef.h as follows:

typedef HANDLE WINSTA;

HWND

A handle to a window.

This type is declared in WinDef.h as follows:

typedef HANDLE HWND;

INT

A 32-bit signed integer. The range is -2147483648 through 2147483647 decimal.

This type is declared in WinDef.h as follows:

typedef int INT;

INT_PTR

A signed integer type for pointer precision. Use when casting a pointer to an integer to perform pointer arithmetic.

This type is declared in BaseTsd.h as follows:

 
#if defined(_WIN64) 
 typedef __int64 INT_PTR; 
#else 
 typedef int INT_PTR;
#endif

INT8

An 8-bit signed integer.

This type is declared in BaseTsd.h as follows:

typedef signed char INT8;

INT16

A 16-bit signed integer.

This type is declared in BaseTsd.h as follows:

typedef signed short INT16;

INT32

A 32-bit signed integer. The range is -2147483648 through 2147483647 decimal.

This type is declared in BaseTsd.h as follows:

typedef signed int INT32;

INT64

A 64-bit signed integer. The range is –9223372036854775808 through 9223372036854775807 decimal.

This type is declared in BaseTsd.h as follows:

typedef signed __int64 INT64;

LANGID

A language identifier. For more information, see Language Identifiers.

This type is declared in WinNT.h as follows:

typedef WORD LANGID;

LCID

A locale identifier. For more information, see Locale Identifiers.

This type is declared in WinNT.h as follows:

typedef DWORD LCID;

LCTYPE

A locale information type. For a list, see Locale Information Constants.

This type is declared in WinNls.h as follows:

typedef DWORD LCTYPE;

LGRPID

A language group identifier. For a list, see EnumLanguageGroupLocales.

This type is declared in WinNls.h as follows:

typedef DWORD LGRPID;

LONG

A 32-bit signed integer. The range is –2147483648 through 2147483647 decimal.

This type is declared in WinNT.h as follows:

typedef long LONG;

LONGLONG

A 64-bit signed integer. The range is –9223372036854775808 through 9223372036854775807 decimal.

This type is declared in WinNT.h as follows:

 
#if !defined(_M_IX86)
 typedef __int64 LONGLONG; 
#else
 typedef double LONGLONG;
#endif

LONG_PTR

A signed long type for pointer precision. Use when casting a pointer to a long to perform pointer arithmetic.

This type is declared in BaseTsd.h as follows:

 
#if defined(_WIN64)
 typedef __int64 LONG_PTR; 
#else
 typedef long LONG_PTR;
#endif

LONG32

A 32-bit signed integer. The range is –2147483648 through 2147483647 decimal.

This type is declared in BaseTsd.h as follows:

typedef signed int LONG32;

LONG64

A 64-bit signed integer. The range is –9223372036854775808 through 9223372036854775807 decimal.

This type is declared in BaseTsd.h as follows:

typedef __int64 LONG64;

LPARAM

A message parameter.

This type is declared in WinDef.h as follows:

typedef LONG_PTR LPARAM;

LPBOOL

A pointer to a BOOL.

This type is declared in WinDef.h as follows:

typedef BOOL far *LPBOOL;

LPBYTE

A pointer to a BYTE.

This type is declared in WinDef.h as follows:

typedef BYTE far *LPBYTE;

LPCOLORREF

A pointer to a COLORREF value.

This type is declared in WinDef.h as follows:

typedef DWORD *LPCOLORREF;

LPCSTR

A pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef __nullterminated CONST CHAR *LPCSTR;

LPCTSTR

An LPCWSTR if UNICODE is defined, an LPCSTR otherwise. For more information, see Windows Data Types for Strings.

This type is declared in WinNT.h as follows:

 
#ifdef UNICODE
 typedef LPCWSTR LPCTSTR; 
#else
 typedef LPCSTR LPCTSTR;
#endif

LPCVOID

A pointer to a constant of any type.

This type is declared in WinDef.h as follows:

typedef CONST void *LPCVOID;

LPCWSTR

A pointer to a constant null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef CONST WCHAR *LPCWSTR;

LPDWORD

A pointer to a DWORD.

This type is declared in WinDef.h as follows:

typedef DWORD *LPDWORD;

LPHANDLE

A pointer to a HANDLE.

This type is declared in WinDef.h as follows:

typedef HANDLE *LPHANDLE;

LPINT

A pointer to an INT.

This type is declared in WinDef.h as follows:

typedef int *LPINT;

LPLONG

A pointer to a LONG.

This type is declared in WinDef.h as follows:

typedef long *LPLONG;

LPSTR

A pointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef CHAR *LPSTR;

LPTSTR

An LPWSTR if UNICODE is defined, an LPSTR otherwise. For more information, see Windows Data Types for Strings.

This type is declared in WinNT.h as follows:

 
#ifdef UNICODE
 typedef LPWSTR LPTSTR;
#else
 typedef LPSTR LPTSTR;
#endif

LPVOID

A pointer to any type.

This type is declared in WinDef.h as follows:

typedef void *LPVOID;

LPWORD

A pointer to a WORD.

This type is declared in WinDef.h as follows:

typedef WORD *LPWORD;

LPWSTR

A pointer to a null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef WCHAR *LPWSTR;

LRESULT

Signed result of message processing.

This type is declared in WinDef.h as follows:

typedef LONG_PTR LRESULT;

PBOOL

A pointer to a BOOL.

This type is declared in WinDef.h as follows:

typedef BOOL *PBOOL;

PBOOLEAN

A pointer to a BOOLEAN.

This type is declared in WinNT.h as follows:

typedef BOOLEAN *PBOOLEAN;

PBYTE

A pointer to a BYTE.

This type is declared in WinDef.h as follows:

typedef BYTE *PBYTE;

PCHAR

A pointer to a CHAR.

This type is declared in WinNT.h as follows:

typedef CHAR *PCHAR;

PCSTR

A pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef CONST CHAR *PCSTR;

PCTSTR

A PCWSTR if UNICODE is defined, a PCSTR otherwise. For more information, see Windows Data Types for Strings.

This type is declared in WinNT.h as follows:

 
#ifdef UNICODE
 typedef LPCWSTR PCTSTR;
#else
 typedef LPCSTR PCTSTR;
#endif

PCWSTR

A pointer to a constant null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef CONST WCHAR *PCWSTR;

PDWORD

A pointer to a DWORD.

This type is declared in WinDef.h as follows:

typedef DWORD *PDWORD;

PDWORDLONG

A pointer to a DWORDLONG.

This type is declared in WinNT.h as follows:

typedef DWORDLONG *PDWORDLONG;

PDWORD_PTR

A pointer to a DWORD_PTR.

This type is declared in BaseTsd.h as follows:

typedef DWORD_PTR *PDWORD_PTR;

PDWORD32

A pointer to a DWORD32.

This type is declared in BaseTsd.h as follows:

typedef DWORD32 *PDWORD32;

PDWORD64

A pointer to a DWORD64.

This type is declared in BaseTsd.h as follows:

typedef DWORD64 *PDWORD64;

PFLOAT

A pointer to a FLOAT.

This type is declared in WinDef.h as follows:

typedef FLOAT *PFLOAT;

PHALF_PTR

A pointer to a HALF_PTR.

This type is declared in BaseTsd.h as follows:

 
#ifdef _WIN64
 typedef HALF_PTR *PHALF_PTR;
#else
 typedef HALF_PTR *PHALF_PTR;
#endif

PHANDLE

A pointer to a HANDLE.

This type is declared in WinNT.h as follows:

typedef HANDLE *PHANDLE;

PHKEY

A pointer to an HKEY.

This type is declared in WinDef.h as follows:

typedef HKEY *PHKEY;

PINT

A pointer to an INT.

This type is declared in WinDef.h as follows:

typedef int *PINT;

PINT_PTR

A pointer to an INT_PTR.

This type is declared in BaseTsd.h as follows:

typedef INT_PTR *PINT_PTR;

PINT8

A pointer to an INT8.

This type is declared in BaseTsd.h as follows:

typedef INT8 *PINT8;

PINT16

A pointer to an INT16.

This type is declared in BaseTsd.h as follows:

typedef INT16 *PINT16;

PINT32

A pointer to an INT32.

This type is declared in BaseTsd.h as follows:

typedef INT32 *PINT32;

PINT64

A pointer to an INT64.

This type is declared in BaseTsd.h as follows:

typedef INT64 *PINT64;

PLCID

A pointer to an LCID.

This type is declared in WinNT.h as follows:

typedef PDWORD PLCID;

PLONG

A pointer to a LONG.

This type is declared in WinNT.h as follows:

typedef LONG *PLONG;

PLONGLONG

A pointer to a LONGLONG.

This type is declared in WinNT.h as follows:

typedef LONGLONG *PLONGLONG;

PLONG_PTR

A pointer to a LONG_PTR.

This type is declared in BaseTsd.h as follows:

typedef LONG_PTR *PLONG_PTR;

PLONG32

A pointer to a LONG32.

This type is declared in BaseTsd.h as follows:

typedef LONG32 *PLONG32;

PLONG64

A pointer to a LONG64.

This type is declared in BaseTsd.h as follows:

typedef LONG64 *PLONG64;

POINTER_32

A 32-bit pointer. On a 32-bit system, this is a native pointer. On a 64-bit system, this is a truncated 64-bit pointer.

This type is declared in BaseTsd.h as follows:

 
#if defined(_WIN64)
 #define POINTER_32 __ptr32
#else
 #define POINTER_32
#endif

POINTER_64

A 64-bit pointer. On a 64-bit system, this is a native pointer. On a 32-bit system, this is a sign-extended 32-bit pointer.

Note that it is not safe to assume the state of the high pointer bit.

This type is declared in BaseTsd.h as follows:

 
#if (_MSC_VER >= 1300)
 #define POINTER_64 __ptr64
#else
 #define POINTER_64
#endif

POINTER_SIGNED

A signed pointer.

This type is declared in BaseTsd.h as follows:

#define POINTER_SIGNED __sptr

POINTER_UNSIGNED

An unsigned pointer.

This type is declared in BaseTsd.h as follows:

#define POINTER_UNSIGNED __uptr

PSHORT

A pointer to a SHORT.

This type is declared in WinNT.h as follows:

typedef SHORT *PSHORT;

PSIZE_T

A pointer to a SIZE_T.

This type is declared in BaseTsd.h as follows:

typedef SIZE_T *PSIZE_T;

PSSIZE_T

A pointer to a SSIZE_T.

This type is declared in BaseTsd.h as follows:

typedef SSIZE_T *PSSIZE_T;

PSTR

A pointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef CHAR *PSTR;

PTBYTE

A pointer to a TBYTE.

This type is declared in WinNT.h as follows:

typedef TBYTE *PTBYTE;

PTCHAR

A pointer to a TCHAR.

This type is declared in WinNT.h as follows:

typedef TCHAR *PTCHAR;

PTSTR

A PWSTR if UNICODE is defined, a PSTR otherwise. For more information, see Windows Data Types for Strings.

This type is declared in WinNT.h as follows:

 
#ifdef UNICODE
 typedef LPWSTR PTSTR;
#else typedef LPSTR PTSTR;
#endif

PUCHAR

A pointer to a UCHAR.

This type is declared in WinDef.h as follows:

typedef UCHAR *PUCHAR;

PUHALF_PTR

A pointer to a UHALF_PTR.

This type is declared in BaseTsd.h as follows:

 
#ifdef _WIN64
 typedef UHALF_PTR *PUHALF_PTR;
#else
 typedef UHALF_PTR *PUHALF_PTR;
#endif

PUINT

A pointer to a UINT.

This type is declared in WinDef.h as follows:

typedef UINT *PUINT;

PUINT_PTR

A pointer to a UINT_PTR.

This type is declared in BaseTsd.h as follows:

typedef UINT_PTR *PUINT_PTR;

PUINT8

A pointer to a UINT8.

This type is declared in BaseTsd.h as follows:

typedef UINT8 *PUINT8;

PUINT16

A pointer to a UINT16.

This type is declared in BaseTsd.h as follows:

typedef UINT16 *PUINT16;

PUINT32

A pointer to a UINT32.

This type is declared in BaseTsd.h as follows:

typedef UINT32 *PUINT32;

PUINT64

A pointer to a UINT64.

This type is declared in BaseTsd.h as follows:

typedef UINT64 *PUINT64;

PULONG

A pointer to a ULONG.

This type is declared in WinDef.h as follows:

typedef ULONG *PULONG;

PULONGLONG

A pointer to a ULONGLONG.

This type is declared in WinDef.h as follows:

typedef ULONGLONG *PULONGLONG;

PULONG_PTR

A pointer to a ULONG_PTR.

This type is declared in BaseTsd.h as follows:

typedef ULONG_PTR *PULONG_PTR;

PULONG32

A pointer to a ULONG32.

This type is declared in BaseTsd.h as follows:

typedef ULONG32 *PULONG32;

PULONG64

A pointer to a ULONG64.

This type is declared in BaseTsd.h as follows:

typedef ULONG64 *PULONG64;

PUSHORT

A pointer to a USHORT.

This type is declared in WinDef.h as follows:

typedef USHORT *PUSHORT;

PVOID

A pointer to any type.

This type is declared in WinNT.h as follows:

typedef void *PVOID;

PWCHAR

A pointer to a WCHAR.

This type is declared in WinNT.h as follows:

typedef WCHAR *PWCHAR;

PWORD

A pointer to a WORD.

This type is declared in WinDef.h as follows:

typedef WORD *PWORD;

PWSTR

A pointer to a null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef WCHAR *PWSTR;

QWORD

A 64-bit unsigned integer.

This type is declared as follows:

typedef unsigned __int64 QWORD;

SC_HANDLE

A handle to a service control manager database. For more information, see SCM Handles.

This type is declared in WinSvc.h as follows:

typedef HANDLE SC_HANDLE;

SC_LOCK

A lock to a service control manager database. For more information, see SCM Handles.

This type is declared in WinSvc.h as follows:

typedef LPVOID SC_LOCK;

SERVICE_STATUS_HANDLE

A handle to a service status value. For more information, see SCM Handles.

This type is declared in WinSvc.h as follows:

typedef HANDLE SERVICE_STATUS_HANDLE;

SHORT

A 16-bit integer. The range is –32768 through 32767 decimal.

This type is declared in WinNT.h as follows:

typedef short SHORT;

SIZE_T

The maximum number of bytes to which a pointer can point. Use for a count that must span the full range of a pointer.

This type is declared in BaseTsd.h as follows:

typedef ULONG_PTR SIZE_T;

SSIZE_T

A signed version of SIZE_T.

This type is declared in BaseTsd.h as follows:

typedef LONG_PTR SSIZE_T;

TBYTE

A WCHAR if UNICODE is defined, a CHAR otherwise.

This type is declared in WinNT.h as follows:

 
#ifdef UNICODE
 typedef WCHAR TBYTE;
#else
 typedef unsigned char TBYTE;
#endif

TCHAR

A WCHAR if UNICODE is defined, a CHAR otherwise.

This type is declared in WinNT.h as follows:

 
#ifdef UNICODE
 typedef WCHAR TCHAR;
#else
 typedef char TCHAR;
#endif

UCHAR

An unsigned CHAR.

This type is declared in WinDef.h as follows:

typedef unsigned char UCHAR;

UHALF_PTR

An unsigned HALF_PTR. Use within a structure that contains a pointer and two small fields.

This type is declared in BaseTsd.h as follows:

 
#ifdef _WIN64
 typedef unsigned int UHALF_PTR;
#else
 typedef unsigned short UHALF_PTR;
#endif

UINT

An unsigned INT. The range is 0 through 4294967295 decimal.

This type is declared in WinDef.h as follows:

typedef unsigned int UINT;

UINT_PTR

An unsigned INT_PTR.

This type is declared in BaseTsd.h as follows:

 
#if defined(_WIN64)
 typedef unsigned __int64 UINT_PTR;
#else
 typedef unsigned int UINT_PTR;
#endif

UINT8

An unsigned INT8.

This type is declared in BaseTsd.h as follows:

typedef unsigned char UINT8;

UINT16

An unsigned INT16.

This type is declared in BaseTsd.h as follows:

typedef unsigned short UINT16;

UINT32

An unsigned INT32. The range is 0 through 4294967295 decimal.

This type is declared in BaseTsd.h as follows:

typedef unsigned int UINT32;

UINT64

An unsigned INT64. The range is 0 through 18446744073709551615 decimal.

This type is declared in BaseTsd.h as follows:

typedef usigned __int 64 UINT64;

ULONG

An unsigned LONG. The range is 0 through 4294967295 decimal.

This type is declared in WinDef.h as follows:

typedef unsigned long ULONG;

ULONGLONG

A 64-bit unsigned integer. The range is 0 through 18446744073709551615 decimal.

This type is declared in WinNT.h as follows:

 
#if !defined(_M_IX86)
 typedef unsigned __int64 ULONGLONG;
#else
 typedef double ULONGLONG;
#endif

ULONG_PTR

An unsigned LONG_PTR.

This type is declared in BaseTsd.h as follows:

 
#if defined(_WIN64)
 typedef unsigned __int64 ULONG_PTR;
#else
 typedef unsigned long ULONG_PTR;
#endif

ULONG32

An unsigned LONG32. The range is 0 through 4294967295 decimal.

This type is declared in BaseTsd.h as follows:

typedef unsigned int ULONG32;

ULONG64

An unsigned LONG64. The range is 0 through 18446744073709551615 decimal.

This type is declared in BaseTsd.h as follows:

typedef unsigned __int64 ULONG64;

UNICODE_STRING

A Unicode string.

This type is declared in Winternl.h as follows:

 
typedef struct _UNICODE_STRING {
  USHORT  Length;
  USHORT  MaximumLength;
  PWSTR  Buffer;
} UNICODE_STRING;
typedef UNICODE_STRING *PUNICODE_STRING;
typedef const UNICODE_STRING *PCUNICODE_STRING;

USHORT

An unsigned SHORT. The range is 0 through 65535 decimal.

This type is declared in WinDef.h as follows:

typedef unsigned short USHORT;

USN

An update sequence number (USN).

This type is declared in WinNT.h as follows:

typedef LONGLONG USN;

VOID

Any type.

This type is declared in WinNT.h as follows:

#define VOID void

WCHAR

A 16-bit Unicode character. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef wchar_t WCHAR;

WINAPI

The calling convention for system functions.

This type is declared in WinDef.h as follows:

#define WINAPI __stdcall

CALLBACK, WINAPI, and APIENTRY are all used to define functions with the __stdcall calling convention. Most functions in the Windows API are declared using WINAPI. You may wish to use CALLBACK for the callback functions that you implement to help identify the function as a callback function.

WORD

A 16-bit unsigned integer. The range is 0 through 65535 decimal.

This type is declared in WinDef.h as follows:

typedef unsigned short WORD;

WPARAM

A message parameter.

This type is declared in WinDef.h as follows:

typedef UINT_PTR WPARAM;

 

 

ref:

http://edisonx.pixnet.net/blog/post/35305668-%5Bc%5D-printf-%E5%BC%95%E6%95%B8%E8%AA%AA%E6%98%8E

http://www.cplusplus.com/reference/cstdio/printf/

https://msdn.microsoft.com/zh-tw/library/s3f49ktz.aspx

https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx

創作者介紹
創作者 天才R 的頭像
天才R

做 個 有 趣 的 人

天才R 發表在 痞客邦 留言(0) 人氣()