Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C language output integer 1234 is 8 bits wide. How to align data to the left?
C language output integer 1234 is 8 bits wide. How to align data to the left?
Call function printf ("%-8d ",); Do it.

Parsing: where "%-8d" is a formatted string, the specified characters in the format begin with "%"followed by one or more specified characters, "-"means left alignment, and no "-"means right alignment. The number "8" indicates that the output width is 8 bits, and "d" indicates that the output type is an integer.

Common descriptors are: %d decimal signed integer, %u decimal unsigned integer, %f floating point number, %s string, %c single character, %p pointer value and %e exponential floating point number.

Extended data:

1, you can insert a number between "%"and letters to indicate the maximum field width. For example, %3d means to output a 3-bit integer, which is not enough for 3-bit right alignment. If you want to add some zeros before the output value, you should add a zero before the field width item. For example, %04d means that when a number less than 4 digits is output, it will be preceded by 0, making its total width 4 digits.

2. You can add a lowercase letter L between "%"and the letter, indicating that the output is a long number. For example, %ld means to output long integers and %lf means to output double floating-point numbers.

3. You can control whether the output is left-aligned or right-aligned, that is, adding a "-"sign between "%"and letters means that the output is left-aligned, otherwise it is right-aligned. For example, %-7d means that the output 7-bit integer is left-aligned.

Baidu Encyclopedia -printf ()