C언어 - printf()함수의 변환 지정자들

2020. 11. 9. 16:42개인공부/C언어

 

 

 

 

 

conversion specifier
conversion specifier

 

 

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <float.h>


int main() 
{
	double d = 3.14159265358979323846264338327950288419716939;
	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);
	printf("%u %u %u\n", 1024, -1, UINT_MAX);

	printf("\n");
	printf("%f %f %lf\n", 3.141592f, d, d); // l in %lf 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.00012345);
	printf("%G %G\n", 0.00012345, 0.00012345);
	
	printf("\n");
	printf("%o\n", 9);
	printf("%p\n", &d); // pointer-of operator

	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;

}

 

 

 

 

Result

 

 

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");

A
I love you
Even if there's a small chance, we owe this to everyone who's not in this room to try.

 

 

 

printf("\n");
	printf("%d %i %i %i\n", 1004, 1234, INT_MAX, UINT_MAX);
	printf("%u %u %u\n", 1024, -1, UINT_MAX);


1004 1234 2147483647 -1
1024 4294967295 4294967295

 

 

double d = 3.14159265358979323846264338327950288419716939;
printf("\n");
	printf("%f %f %lf\n", 3.141592f, d, d); // l in %lf is ignored
	printf("%a %A\n", d, d);
	printf("%e %E\n", d, d);


3.141592 3.141593 3.141593
0x1.921fb54442d18p+1 0X1.921FB54442D18P+1
3.141593e+00 3.141593E+00

 

 

 

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.00012345);
	printf("%G %G\n", 0.00012345, 0.00012345);


123457 1.23457e+06
123457 1.23457E+06
0.00012345 0.00012345
0.00012345 0.00012345

 

printf("\n");
	printf("%o\n", 9);
	printf("%p\n", &d); // pointer-of operator


11
00DAF8FC

 

 

	printf("\n");
	printf("%x %X\n", 11, 11);
	printf("%%\n", d); // Note the warning. d is ignored.


b B
%

 

 

	printf("\n");
	printf("%9d\n", 12345);
	printf("%09d\n", 12345);
	printf("%.2f\n", 3.141592);
	printf("%.20f %.20lf\n", d, d);


    12345
000012345
3.14
3.14159265358979311600 3.14159265358979311600

 

 

	printf("\n");
	int n_printed = printf("Counting!");
	printf("%u\n", n_printed);


Counting!9

'개인공부 > C언어' 카테고리의 다른 글

C언어 - 연산자  (0) 2020.11.09
C언어 - scanf() 함수의 사용법  (0) 2020.11.09
C언어 - strlen() 함수  (0) 2020.11.09
C언어 - 문자열이 메모리에 저장되는 구조  (0) 2020.11.09
C언어 - 문자열 입출력하기  (0) 2020.11.09