Different formats and principle analysis of lattice number output in C serial 8-printf

Time:2020-7-26

1、 Different output formats have different results

1.% LD is used for the value of long type. If the size of int and long in the system is the same, use% d. such programs can be transplanted to other systems (the sizes of int and long types are different).

2. Similarly, the front of X and O can also be modified with L.

3. For short type, h is used as prefix.

4. Both the H and l prefixes can be used together with u to represent an unsigned type. E.g.:% Lu

 

/*Print2. C -- more features of printf()*/

#include

int main(void) {

  Signed int UN = 30000000; / * systems with 32-bit int and 16 bit short*/

  short end = 200;

  long big = 65537;

  long long verybig = 1234567890642;

​

  printf("un= %u and not %d \n", un, un);

  printf("end = %hd and %d \n", end, end);

  printf("big = %ld and not %hd", big, big);

  printf("verybig = %lld and not %ld \n", verybig, verybig);

​

  return 0;

}

Analysis:

(1) From the data generated above, we can see that in the first line, the number 3000000 is stored in the system in the same way, but we use different printing methods, so we get different results. This occurs when the value to be printed is greater than the maximum value of the signed value.

(2) The second line, the question in, is that the C compiler automatically converts the short type to an int type value. Why?

Because the int type is considered to be the most efficient type for computers to handle integer types.

(3) What’s the function of the H modifier here?

Using the H modifier can display the situation that larger integers are truncated into short type values. For example, 65537 is represented in binary form as 0.0000000.1 billion, and only the following 16 bits will be viewed when using% HD;

Episode:

I installed visual studio 2019 this evening, but I wrote a small program, which is to compile and report errors

Error: unable to find the… EXE file, after multiple verification, it took a long time to get it right.

Let’s create a new “empty project” (no other option)

 

 

Then create an empty project, and then right-click “source file”, Select the C + + project (we can manually change it to C project, that is, the suffix name can be changed directly to. C), and then edit the code. First, we need to click build – build solution, and then click run directly to run normally. If we don’t click build solution first, we will report an error. ​

3、 Source code:

D8_1_print.c

https://github.com/ruigege66/CPrimerPlus/blob/master/D8_1_print.c

D7_toobig.c

https://github.com/ruigege66/CPrimerPlus/blob/master/D7_toobig.c

2.CSDN:https://blog.csdn.net/weixin_44630050

3. Blog Garden: https://www.cnblogs.com/ruigege0000/

4. welcome to WeChat official account: Fourier transform, personal account, only for technology exchange, backstage reply “gift package” to get Java big data learning video package.