Printf Cheat Sheet



Oct 27, 2020 Download Now: Basic Linux Commands Cheat Sheet Linux System Administration Skills Assessment The printf command traces its roots back to the development world but offers practical utility to the sysadmin, as well. Printf and scanf are the two standard C programming language functions for console input and output. A variation of these commands ( fprintf and fscanf ) also allows I/O to files. Another ( sprintf and sscanf ) allows I/O to strings.

Printf exampleCheatPrintf

Java’s printf() is a method that is used for formatting data output and is a combination of String.format() and out.print(). The types of formatting include:

  • flags
  • width
  • precision
  • conversions
C printf cheat sheet

General Equation: %[flag][width][.precision][conversion]

Flags: plus(+) or minus(-) sign, zero-padding, comma delimiter, and left justify.
Width: minimum amount of spaces data takes up.
Precision: amount of digits after decimal (only applies to floating points).
Conversion: decimal integer(d), floating point(f), char(c), String(s), boolean(b), and hashcode(h).

Printf Cheat Sheet

Decimal Integerbyte, short, int, long
Floating Pointfloat, double

Cheat Sheet Recipes

[Example][Example]
[Resource][Resource]
[Resource][Resource]

C Language Cheat Sheet


General
%ccharacter
%Cconverts to uppercase character (if not already)
%ddecimal integer (base 10)
%escientific notation
%Escientific notation with a capital ‘E’
%ffloating-point number
%iinteger (base 10)
%bconverts to boolean
%Bconverts to uppercase boolean
%ooctal number (base 8)
%sa string of characters
%Sconverts to a string of uppercase characters (if not already)
%uunsigned decimal integer
%hconverts to hashcode
%Hconverts to uppercase hashcode
%xnumber in hexadecimal (base 16)
%%prints a percent sign
%prints a percent sign

Decimal Integer
%0Xdzero-fill for X digits
%Xdright justify for X digits
%-Xdleft justify for X digits
%+dadds plus sign(+) to positive integers, minus sign for negative integers(-)
% dprints minus sign(-) if integer is negative, prints a space elsewise
%,duses comma delimiter between every 3 digits (ex: 1,000)

Floating Point
%.Yfprints Y positions after decimal
%Xftakes up X spaces
%0X.Yfzero-fills
%-X.Yfleft justifies

String
%Xsformats string for a minimum of X spaces
%-Xsleft justify

Special Characters
aaudible alert
bbackspace
fform feed
nnewline or linefeed
rcarriage return
ttab
vvertical tab
backslash




Comments are closed.