From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/FUNCTIONS/printf.html | 106 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 reference/C/FUNCTIONS/printf.html (limited to 'reference/C/FUNCTIONS/printf.html') diff --git a/reference/C/FUNCTIONS/printf.html b/reference/C/FUNCTIONS/printf.html new file mode 100644 index 0000000..111a8e7 --- /dev/null +++ b/reference/C/FUNCTIONS/printf.html @@ -0,0 +1,106 @@ +printf function + + + + + + +
+
+

printf function

+
+
+

+printf is used to O/P data to +STDOUT (usually the screen). It has many +formatting options which we shall look at in a moment. + +


+

printf syntax

+This is an example of printf in its simplest form. +

+

+ + + + +
+
+
+  #include <stdio.h>
+
+  main()
+  {
+    printf("This text will appear on the screen\n");  
+  }
+
+
+
+

+printf is passed one formatting argument. +The unusual thing about the example (in my mind) is \n, this is actually +an escape sequence that signals a new line. Without +it, any printf's +that follow would O/P to the same line. +printf also takes extra arguments which are inserted into the format +string at locations marked with a %. +

+

+ + + + +
+
+
+  #include <stdio.h>
+
+  main()
+  {
+    int number=42;
+    printf("The answer is %i\n", number);  
+  }
+
+
+
+

+What happens here is the %i is seen as a +formatting identifer for the +next argument (number). In this case an integer is expected.

+ +


+

See also

+
    +
  1. puts Much easier to use - but not as powerfull. +
  2. sprintf Same as 'printf' but O/P to a string array. +
  3. Strings. +
  4. A dead handy printf idiom.. +
+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + -- cgit v1.2.3-54-g00ecf