2018-10-18 22:15:32 C language
Output various types of data on the screen
- We use puts to output strings. Puts is an abbreviation for output string, can only be used for outputting strings, cannot output integers, decimals, characters, etc., we need to use another function, that is printf. printf is the abbreviation for print format, meaning "format printing".
- %c: Outputs one character. c is shorthand for character. %s: Output a string. S is shorthand for string. %f: Outputs a decimal. F is a shorthand for float.
\n
is a whole, grouped together to represent a newline character. Line break is a control character in ASCII encoding, cannot be entered directly on the keyboard, can only be represented by this special method, known as the escape character, we will be in the "C Language escape character" section of the specific explanation, please let us briefly remember \n
the meaning.
- The difference between puts and printf when outputting a string: The puts output is wrapped, and printf does not have to add the line break itself.
- Money's output value is not 93.96, but a very close value, which is related to the storage mechanism of the decimal itself, which causes many decimals to not be accurately represented.
- We can also output the data directly without the use of variables.
What does the%ds output? From the output can be found, %d
is replaced by the value of the variable a, without s
changing, as is output. This is because the %d
format control, together with %ds
no meaning, s
is simply followed %d
by a normal character, so it will be output as is.
How to write long text in a string: You can divide long text into several strings in the output statement.
2018-10-18 22:15:32 C language