Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- web
- Math
- DP
- server
- String
- udemy
- graph
- dfs
- C언어
- php
- BOJ
- Cleancode
- 따라하며 배우는 C언어
- BFS
- 생활코딩
- 인프런
- 백준
- BASIC
- C
- 정수론
- greedy
- 따라하면서 배우는 C언어
- Python
- 종만북
- Algorithm
- 따배씨
- programmers
- Algospot
- JavaScript
- sorting
Archives
- Today
- Total
몽상실현개발주의
[따배씨] 4.7 pritnf() 함수의 변환 지정자 본문
따배씨 - 따라하며 배우는 C언어
4강 문자열과 형식 맞춘 입출력
4.7 pritnf() 함수의 변환 지정자 Conversion Specifiers
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main()
{
double d = 3.14159265358979323846264338327950288419716939937510;
printf("%c\n", 'A');
printf("%s", "I love you\n");
printf("Even if there's a small chance, \
we owe this to everyone who's not in this room to try.\n");
printf("\n");
printf("%d %i %i %i\n", 1004, 1234, INT_MAX, UINT_MAX); // Note overflow
printf("%u %u %u\n", 1024, -1, UINT_MAX); // Note overflow
printf("\n");
printf("%f %f %lf\n", 3.141592f, d, d); // l in %f is ignored
printf("%a %A\n", d, d);
printf("%e %E\n", d, d);
printf("\n");
printf("%g %g\n", 123456.789, 1234567.89);
printf("%G %G\n", 123456.789, 1234567.89);
printf("%g %g\n", 0.00012345, 0.000012345);
printf("%G %G\n", 0.00012345, 0.000012345);
printf("\n");
printf("%o\n", 9);
printf("%o\n", 9);
printf("%p\n", &d); // pointer-of perator
printf("n");
printf("%x %X\n", 11, 11);
printf("%%\n", d); // Note the warning. d is ignored.
printf("\n");
printf("%9d\n", 12345);
printf("%09d\n", 12345);
printf("%.2f\n", 3.141592);
printf("%.20f %.20lf\n", d, d);
printf("\n");
int n_printed = printf("Counting!");
printf("%u\n", n_printed);
return 0;
}
printf("%f %f %lf\n", 3.141592f, d, d); // l in %f is ignored
- double 을 출력할때 %f 가 float이 아닌 double을 출력하는 것으로 자동으로 바뀜
printf("%p\n", &d); // pointer-of perator
- d 변수의 주소값 출력
printf("%9d\n", 12345);
// 12345
printf("%09d\n", 12345);
// 000012345
printf("%.2f\n", 3.141592);
// 3.14
printf("%.20f %.20lf\n", d, d);
// 3.14159265358979311600 3.14159265358979311600
- 자리수 맞춰 출력
- %숫자 - 오른쪽 정렬 자리수 맞추기, 모자란 자리수는 빈칸 처리
- %0숫자 - 오른쪽 정렬 자리수 맞추기, 모자란 자리수는 0으로 처리
- %.숫자f, %.숫자lf - 소숫점 이하자리 자리수 출력수 정하기
int n_printed = printf("Counting!");
printf("%u\n", n_printed);
// 9
- printf 의 리턴 값이 존재, 출력하는 글자 수를 리턴
이 글의 모든 사진과 내용의 출처는 홍정모 교수님께 있음을 알려드립니다.
http://blog.naver.com/atelierjpro
http://www.inflearn.com/course/following-c
'Language > C' 카테고리의 다른 글
[따배씨] 4.9 printf() 함수가 인자들을 해석하는 과정 (0) | 2021.05.14 |
---|---|
[따배씨] 4.8 변환 지정자의 수식어들 (0) | 2021.05.14 |
[따배씨] 4.5 기호적 상수와 전처리기 ~ 4.6 명백한 상수들 (0) | 2021.05.13 |
[따배씨] 4.4srlen() 함수 (0) | 2021.05.13 |
[따배씨] 4.3 문자열이 메모리에 저장되는 구조 (0) | 2021.05.12 |
Comments