简体   繁体   中英

What's the difference between %c and %C in printf?

I can only find references for small c. I assume that the capital C is for Unicode, but I'm not sure. For lower numbers, both output the same character.

From MSDN

%c

When used with printf functions, specifies a single-byte character; when used with wprintf functions, specifies a wide character.

%C

When used with printf functions, specifies a wide character; when used with wprintf functions, specifies a single-byte character.

From MSDN:

%c

type: int or wint_t 

When used with printf functions, specifies a single-byte character; when used with wprintf functions, specifies a wide character.

%C

type: int or wint_t

When used with printf functions, specifies a wide character; when used with wprintf functions, specifies a single-byte character.

more about format specifiers here

Note that %C isn't standard. Standard conversion for characters are:

  • %c is used for a int . printf output it as it if was an unsigned char . wprintf output the result of the convertion to a wchar_t by btowc .
  • %lc is used for a wint_t . printf output the result of the conversion to a multibyte string by wcrtomb . wprintf output it as if it was a wchar_t .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM