Why use the output controller:
We know that the data in the computer is stored in the form of binary, but the code composed of 01 can represent both data and instructions. It's easy to misunderstand if you don't use the output controller to become what you want.
If the 01 code 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 (length is OK) (use hex output)
%o ------------ integer (length is OK) (octal output)
%s ------------ string
Code demo
/* ----------------2020/3/13 21:45--------------- Objective: To explore the non - binary control output character */ # include<stdio.h> int main(void) { int i=10; char a='a'; float b=2.123459789; double c=3.123456789; //%d is generally used for int type. Indicates output in decimal printf("%d\n",i); //%ld for long int type printf("%d\n",i); //%c for output string 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; } /* --------------------vc++6.0 Results of running on------------------ 10 10 a 2.123460 3.123457 --------------------------------------------------------- Experience: We can see that the output of floating-point number is up to six decimal places, both single precision and double precision are the same. Floating point numbers that exceed six digits are rounded off from the seventh digit. No matter how large the eighth digit is, the number after the seventh digit has nothing to do with it. It only depends on whether the seventh digit is rounded Floating point numbers less than six digits are followed by 0 */
Hexadecimal output controller
- Code demo
/* -----------------2020/3/13 22:35---------------- Objective: On the control of base output character */ # include<stdio.h> int main(void) { int i=30; //Output in octal printf("%o\n",i); //Enter the lowercase o printf("%O\n",i); //Uppercase O entered printf("%0\n",i); //Number zero entered printf("%#o\n",i); / / enter the pound sign and lowercase letter o printf("%#O\n",i); printf("----------------\n"); //Hex output printf("%x\n",i); //Enter lowercase x printf("%X\n",i); //The input is an uppercase X printf("%#x\n",i); / / enter the pound sign and lowercase o printf("%#X\n",i); / / enter the pound sign and lowercase o return 0; } /* ---------vc++6.0 Results of running in-------------- 36 O 036 O ---------------- 1e 1E 0x1e 0X1E ------------------------------------------ Experience: Write o in octal to output an unsigned octal number. O in uppercase looks like zero, but o in uppercase is zero. And the number 0 is a blank line So in octal, only lowercase o can output data, andාo can output signed octal numbers In hexadecimal case x can output data. X outputs more than 10 uppercase characters. Lowercase must be lowercase characters. #X signed hexadecimal number. The reason why case can be output in hexadecimal and only lowercase can be output in octal may be because more than 10 parts of hexadecimal are represented by letters. Case can be used. Octal numbers are not case sensitive */ }