C変換指定子および修飾子への便利なリファレンス
この投稿では、すべての人に役立つリファレンスを作成したいと思います。C変換指定子あなたは、一般的にで使用することができますprintf()
、scanf()
および同様のI / O機能。
指定子 | 意味 |
---|---|
%d /%i |
符号付き10進整数 |
%u |
符号なし10進整数 |
%c |
署名なしchar |
%s |
ストリング |
%p |
16進形式のポインター |
%o |
符号なし8進整数 |
%x /%X |
符号なし16進数 |
%e |
指数形式の浮動小数点数e 表記 |
%E |
指数形式の浮動小数点数E 表記 |
%f |
double 10進形式の数値 |
%g /%G |
double 値に応じて、10進形式または指数形式の数値 |
これらの指定子に加えて、次のセットがあります修飾子。
から始めましょう数字。間の数字を使用する%
そしてフォーマット指定子で、最小フィールド幅を知ることができます。例:%3d
印刷された数に関係なく、3つのスペースを取ります。
この:
printf("%4d\n", 1);
printf("%4d\n", 12);
printf("%4d\n", 123);
printf("%4d\n", 1234);
印刷する必要があります
1
12
123
1234If you put a dot before the digit, you are not telling the precision: the number of decimal digits. This of course applies to decimal numbers. Example:
printf("%4.2f\n", 1.0);
printf("%4.3e\n", 12.232432442);
printf("%4.1e\n", 12.232432442);
printf("%4.1f\n", 123.22);
will print:
1.00
1.223e+01
1.2e+01
123.2In addition to digits, we have 3 special letters: h
, l
and L
.
h
, used with integer numbers, indicates a short int
(for example %hd
) or a short unsigned int
(for example %hu
)
l
, used with integer numbers, indicates a long int
(for example %ld
) or a long unsigned int (for example %lu
).
L
, used with floating point numbers, indicates a long double
, for example %Lf
Download my free C Handbook
More clang tutorials:
- Introduction to the C Programming Language
- C Variables and types
- C Constants
- C Operators
- C Conditionals
- How to work with loops in C
- Introduction to C Arrays
- How to determine the length of an array in C
- Introduction to C Strings
- How to find the length of a string in C
- Introduction to C Pointers
- Looping through an array with C
- Booleans in C
- Introduction to C Functions
- How to use NULL in C
- Basic I/O concepts in C
- Double quotes vs single quotes in C
- How to return a string from a C function
- How to solve the implicitly declaring library function warning in C
- How to check a character value in C
- How to print the percentage character using `printf()` in C
- C conversion specifiers and modifiers
- How to access the command line parameters in C
- Scope of variables in C
- Can you nest functions in C?
- Static variables in C
- C Global Variables
- The typedef keyword in C
- C Enumerated Types
- C Structures
- C Header Files
- The C Preprocessor