C 中格式說明符用於輸入和輸出目的。使用這個概念,編譯器可以了解在使用 scanf() 函數取得輸入並使用 printf() 函數列印期間變數中的資料類型。以下是格式說明符的清單。
#類型 | |
---|---|
# %c | |
%d | |
%e 或%E | |
%f | |
%g或%G | |
%hi | |
%hu | |
%i | |
%l 或%ld 或% li | |
%lf | |
%Lf | |
%lu | |
%lli 或%lld | |
%llu | |
%o | |
#%p | |
%s | |
%u | |
%x 或%X | |
%n |
列印%字元
#include <stdio.h> main() { char ch = 'B'; printf("%c</p><p>", ch); //printing character data //print decimal or integer data with d and i int x = 45, y = 90; printf("%d</p><p>", x); printf("%i</p><p>", y); float f = 12.67; printf("%f</p><p>", f); //print float value printf("%e</p><p>", f); //print in scientific notation int a = 67; printf("%o</p><p>", a); //print in octal format printf("%x</p><p>", a); //print in hex format char str[] = "Hello World"; printf("%s</p><p>", str); printf("%20s</p><p>", str); //shift to the right 20 characters including the string printf("%-20s</p><p>", str); //left align printf("%20.5s</p><p>", str); //shift to the right 20 characters including the string, and print string up to 5 character printf("%-20.5s</p><p>", str); //left align and print string up to 5 character }
B 45 90 12.670000 1.267000e+001 103 43 Hello World Hello World Hello World Hello Hello
以上是在C語言中的格式說明符的詳細內容。更多資訊請關注PHP中文網其他相關文章!