You are here:About>Computing & Technology>C / C++ / C#> C> C Tutorials> Specifying Output Formats
About.comC / C++ / C#

C Tutorial Lesson Two - Handling Numbers

From David Bolton,
Your Guide to C / C++ / C#.
FREE Newsletter. Sign Up Now!

Specifying Output Formats in Printf

Printf() is a very powerful function. It can display multiple variables in one statement with a wide range of output formats. It is a variadic function taking a varying number of parameters.

The format of printf is like this:

printf("output String including 0 or more Format Specifiers", expression1,expression 2...expression n) ;

A Format Specifier is a two character symbol. The frst character is always a % and the second a letter from the list below. Here is a full list of Format Specifiers.

%c The character format specifier.
%d The integer format specifier.
%i The integer format specifier (same as %d).
%f The floating-point format specifier.
%e The scientific notation format specifier.
%E The scientific notation format specifier.
%g Uses %f or %e, whichever result is shorter.
%G Uses %f or %E, whichever result is shorter.
%o The unsigned octal format specifier.
%s The string format specifier.
%u The unsigned integer format specifier.
%x The unsigned hexadecimal format specifier.
%X The unsigned hexadecimal format specifier.
%p Displays the corresponding argument that is a pointer.
%n Records the number of characters written so far.
%% Outputs a percent sign.

Additionally we can add modifers to specify the width of the output fields. On the next page we'll see this and some examples.

On the Next Page : Learn more about Format specifiers.

  1. All About Numbers in C
  2. More About Ints
  3. Precision Arithmetic
  4. Learn about Arithmetic Operations
  5. Specifying Output Formats in Printf
  6. Learn how to use Format Specifiers

<< Previous | Next >>

 All Topics | Email Article | Print this Page | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.