Special Application of Formatted Output in C Language

Special Application of Formatted Output in C Language

%c Output in character form
%d Decimal integer
%o Unsigned octal integer
%f Floating point number in decimal form
%s String
%p Pointer

%u Unsigned decimal integer
%e Floating point number, in the form of exponent e
%E Floating point number, in the form of exponent E
%x Unsigned hexadecimal integer, represented by 0~f
%X Unsigned hexadecimal integer, in the form of 0~F means
%ld long integer (note that l is the English letter l, not the number 1)

{
    
    	
	int a = 123;
	int *p = &a;
	float f = 12.345;
	
	printf("%p\n", p);	
	printf("%d%d", a, a);
	printf("\n");
	printf("%5d%5d", a, a);
	printf("\n");
	printf("%-5d%-5d", a, a);
	printf("\n");
	printf("%f\n", f);
	printf("%0.1f\n", f);
	printf("%0.2f\n", f);
}
// 格式化输出例子
0x7fff00edf788
123123
  123  123
123  123  
12.345000
12.3
12.35

%p outputs the value of the pointer p (that is, the address)

a = 123; f = 12.345;
%d: decimal output, %5d: the output width is 5, if it is less than 5, the left space will be filled (right alignment), %-5d: the
output width is 5, if it is less than 5, it will be right Side padding ( minus sign: left alignment ).
%f: floating-point output, %0.1f : floating-point output, keep one decimal place (rounded),
%0.2f: floating-point output, keep two decimal places (rounded).

Guess you like

Origin blog.csdn.net/William_swl/article/details/120378223