Detailed explanation of output controller

Time:2021-4-1

Why use output controllers:

  • We know that in the computer, data is stored in the form of binary in the computer, but the code composed of 01 can represent both data and instructions. It’s easy to misunderstand if we don’t use the output controller to become what we want.

  • If the code composed of 01 represents data, then different output formats of the same 01 code combination will have different output results. So you need to use the output controller

Common output controllers include the following:

%d ————— int

%ld ————— long int

%c ————— char

%f ————— float

%lf ————— double

%X (or% x, the latter% # – x) —- integer (both long and short) (used for hexadecimal output)

%O ——– integer (both long and short) (octal output)

%S ——– string

Code demonstration

/*

  ----------------2020/3/13 21:45---------------
 
  Objective: To explore the non binary control output symbol

*/
# include
int main(void)
{
	int i=10;
	char a='a';
	float b=2.123459789;
	double c=3.123456789;

	//%D is usually used for int type. Indicates that the decimal system is used for output
	printf("%d\n",i);

	//%LD represents the long int type
	printf("%d\n",i);

	//%C is used to output strings
	printf("%c\n",a);

	//%F is used to output single precision floating point numbers
	printf("%f\n" ,b);

	//%LF is used to output double precision floating point numbers
	printf("%lf\n" ,c);

	
	return 0;
}
/*

--------------------The result of running on VC + + 6.0------------------
10
10
a
2.123460
3.123457
---------------------------------------------------------

Experience:

  We can see that floating-point number output is at most six digits after the decimal point, regardless of single precision or double precision is the same.
  Floating point numbers with more than six bits are rounded off from the seventh bit. No matter how big the eighth bit is, the number after the seventh bit has nothing to do with this number. Just see if the seventh place is rounded
  Floating point numbers with less than six digits are followed by zeros

*/

The output controller of base

  • Code demonstration
/*

  -----------------2020/3/13 22:35----------------
  Objective: To investigate the mechanism of the disease
  Research on the control of binary output symbol

*/
# include
int main(void)
{
	int i=30;

	//Output in octal
	Printf (% o-n ", I); // input lowercase o
	Printf (% o-n ", I); // the uppercase o of the input
	Printf (% 0-n ", I); // the number of zeros entered
	Printf ("% #########################
	printf("%#O\n",i);
	
	printf("----------------\n");

	//Hexadecimal output
	Printf (% x-n ", I); // input lowercase x
	Printf (%% x-n ", I); // input an uppercase X
	Printf ("% #########################
	Printf ("% ###################x", I); // enter the well number and small letter O
	return 0;

}
/*

---------The result of running in VC + + 6.0--------------
36
O

036
O
----------------
1e
1E
0x1e
0X1E
------------------------------------------

  Experience:
  
  In the octal small write O output without a sign of the octal number. The capital O and the number zero look similar, but entering the capital o results in a zero. And the number zero is a blank line
  So in octal, only lowercase o can output data, and#o can output signed octal numbers

  In the hexadecimal case x can output data. X outputs more than 10 uppercase characters. Lowercase characters are lowercase characters. #X is a signed hexadecimal number.

  In hexadecimal, both cases can be output, while in octal, only lowercase can be output. The reason may be that more than 10 parts in hexadecimal are represented by letters. You can use case. Octal is a number and cannot be distinguished by case

*/
}