4.1.1.The printf Function
- printf displays information on screen.
- printf returns the number of characters printed.
- printf displays the text you put inside the double quotes.
- printf requires the backslash character - an escape sequence - to display some special characters.
- printf can display variables by using the % conversion character.
- printf format: a string argument followed by any additional arguments.
|
4.1.2.The printf() Conversion Characters and flags
|
Conversion Character |
Displays Argument (Variable's Contents) As |
%c |
Single character |
%d |
Signed decimal integer (int) |
%e |
Signed floating-point value in E notation |
%f |
Signed floating-point value (float) |
%g |
Signed value in %e or %f format, whichever is shorter |
%i |
Signed decimal integer (int) |
%o |
Unsigned octal (base 8) integer (int) |
%s |
String of text |
%u |
Unsigned decimal integer (int) |
%x |
Unsigned hexadecimal (base 16) integer (int)
|
|
4.1.3.Placeholders
The general form of a placeholder is: % flags field-width precision prefix type-identifier.
4.1.5.printf() Escape Sequences
|
Sequence |
Meaning |
\a |
Beeps the speaker |
\b |
Backspace (moves the cursor back, no erase) |
\f |
Form feed (ejects printer page; may clear the screen on some computers) |
\n |
Newline, like pressing the Enter key |
\r |
Carriage return (moves the cursor to the beginning of the line) |
\t |
Tab |
\v |
Vertical tab (moves the cursor down a line) |
\\ |
The backslash character |
\' |
The apostrophe |
\" |
The double-quote character |
\? |
The question mark |
\0 |
The "null" byte (that's 0, not the letter O) |
\Onn |
A character value in octal (base 8) |
\xnnn |
A character value in hexadecimal (base 16) |
|
4.2.1.c: convert value to unsigned char and display
#include <stdio.h> main() { int i = 100; printf(" %c\n",i); }
|
----------------------------------------------------------------------------------------------------------------------------
正因为有了你的关注,我们的生活才更美好。
欢迎各位与我联系
******** Email ******** : xinzhushi@gmail.com .
******** QQ ******** : 543104011 .
******** MSN ******** : shi-java@hotmail.com .