Contents

Syntax

printf("ControlString", arg1, …, argN);

Key Points

1    {
2          int a = 5;
3          int b = 10;
4          printf("a = %d\nb = %d\n", a, b);
5    }

printf2

The code above would produce the following output:

a = 5
b = 10
_

Where "_" indicates the position of the cursor at the end of the operation.

Back to top

Format Specifiers

Format SpecifierMeaning
%cSingle character
%sString (all characters until '\0')
%dSigned decimal integer
%oUnsigned octal integer
%uUnsigned decimal integer
%xUnsigned hexadecimal integer with lower case digits (e.g. 1a5e)
%XSame as %x but with upper case digits (e.g. 1A5E)
%fSigned decimal value (floating point)
%eSigned decimal value with exponent (e.g. 1.26e-5)
%ESame as %e but uses upper case E for exponent (e.g. 1.26E-5)
%gSame as %e or %f, depending on size and precision of value
%GSame as %g but will use capital E for exponent

Back to top