원문 : http://devanix.tistory.com/283
"%[parameter][flags][width][.precision][length]type"
Parameter
|
Character |
Description |
|
n$ |
파라미터 지정 This is a POSIX extension and not in C99. Example: printf("%2$d %1$#x %1$d",16,17) produces "17 0x10 16" |
Flags
|
Character |
Description |
|
+ |
양수 '+', 음수 '-' 기호 출력. (디폴트 : 아무것도 표시 안함) |
|
- |
좌측 정렬 |
|
# |
8진수, 16진수 출력시 각각 0과 0x를, 실수의 경우 소수점 이하 0을 출력 |
|
' '공백 |
출력할 크기가 0보다 클 때 수의 앞에 빈 칸 하나 출력 |
|
0 |
빈공간을 0으로 체움 |
Width
|
Character |
Description |
|
* or N |
폭 지정 (*와 같은 경우 숫자와 대응) Example: printf("%*d", 5, 10) will result in " 10" being printed with a width of 5. |
Precision
|
Character |
Description |
|
* or N |
정밀도 지정 (*와 같은 경우 숫자와 대응) 정수의 경우-> 지정한 숫자보다 개수가 작을 경우 나머지 0으로 표시 실수의 경우-> 소수점 자리 수 문자열의 경우-> 지정한 개수만큼의 문자 표시 Example: printf("%.*s", 3, "abcdef") will result in "abc" being printed. |
Length
|
Character |
Description |
|
h |
정수 자료형 감소 (ind-> short) |
|
hh |
정수 자료형 2번 감소 (ind-> short-> char) |
|
l |
정수 자료형 증가(int-> long) |
|
ll |
정수 자료형 2번 증가(int-> long-> long long) |
|
L |
실수 자료형 증가 (long -> long double) |
|
z |
For integer types, causes printf to expect a size_t sized integer argument. |
|
j |
For integer types, causes printf to expect a intmax_t sized integer argument. |
|
t |
For integer types, causes printf to expect a ptrdiff_t sized integer argument. |
Type
|
Character |
Type |
Description |
|
d, i |
int |
부호 있는 10진수 정수 |
|
u |
unsigned int |
부호 없는 10진수 정수 |
|
o |
unsigned int |
부호 없는 8 진수 정수 |
|
x, X |
unsigned int |
부호 없는 16진수 정수 |
|
f, F |
double |
10진수 방식의 부동 소수점 실수 |
|
e, E |
double |
지수 형식으로 출력 |
|
g, G |
double |
%e와 %f 중 짧은 쪽, 소수점에 이어지는 0은 생략 |
|
c |
int |
값에 대응하는 문자 |
|
s |
char * |
문자열 |
|
p |
void * |
포인터 주소값 |
|
n |
int * |
포인터 주소값 |
|
% |
literal '%' |
리터럴 '%' 문자( 플래그, 폭, 정밀, 길이 허용 안함) |
'프로그래밍 > C++' 카테고리의 다른 글
| 비트연산 정리 (1) | 2011.11.21 |
|---|---|
| C 언어 레퍼런스 - localtime 함수 (0) | 2011.10.13 |
| [System Call] 메모리 맵 - mmap(), munmap(), msync() (0) | 2011.03.04 |
| [C++] 상속 두번째, 세가지 형태의 상속 (private, protected, public) (0) | 2011.03.03 |
| 매크로 (0) | 2010.12.21 |
| Unicode 와 ANSI 문자의 변환을 해주는 매크로 (0) | 2010.12.11 |
| 가변인자 사용하기 (0) | 2010.11.12 |
| const 위치에 따른 동작 (0) | 2010.11.12 |
| 함수 포인터 (0) | 2010.11.11 |
| C++ 파일 입출력 (0) | 2010.10.27 |