Output statements take a format specifier which controls the look of the displayed items. Input statements also use a format to control the interpretation of input.
In the print
version of output (compare with write
) the format specifier is the part before the (unquoted) comma. In all forms of I/O the format may be specified by one of three ways:
- using a
*
(so-called list-directed I/O);
- using a label for a
format
statement;
- using a character expression (variable or constant).
The form in the question is this third.
A character expression for a format specification is made up of a number of parts. The quotes here are simply a delimiter for the string.
First is the mandatory pair of parentheses, leading to the shortest format specification '()'
(which prints nothing).
Next, are format items which may be:
- character literal constants;
- edit descriptors;
- control descriptors;
- a collection of further format items.
Format items may have a repeat count ahead of them.
To answer the question as asked I'll consider just the edit and control descriptors of the format specifications quoted. Wider details of other descriptors (and more detail on the ones here) and formatting may be found elsewhere with the newly gained knowledge on search terms.
There are two edit descriptors here: a
and i
. There is one control descriptor x
.
a
specifies output of a string and i
an integer. i5
says the output will be width five (blank padded if the integer has fewer than five digits on output); a
leads to width the length of the character expression for output.
The control descriptor x
inserts a blank. 2x
is a blank with repeat count 2: giving two spaces output.
So: the first line prints out three strings with spaces between them (here any trailing blanks from the variables will also appear). The second prints the eight integer elements of the array where each field has a width of five.
Each print
statement also gives a newline.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…