Show Menu
Cheatography

C Basics Cheat Sheet (DRAFT) by

A quick reference for my class: CSCV 352 System Programming + Unix

This is a draft cheat sheet. It is a work in progress and is not finished yet.

C Program Structure

/* multi-line */
comment
// single­-line
comment
prepro­cessing commands
includes header files, define constants and enum
global declar­ations
declare global variables
prototype functions
declare functions under main
int main (void)
{
start of program execution
  local declar­ations;
  executable statem­ents;
the program
  return 0;
}
end of program
user function()
{
  function defini­tion;
}
user defined functions referenced in main

C Data Keywords

Original K&R Keywords
C90 K&R Keywords
C99 Keywords
int
signed
_Bool
long
void
_Complex
short
 
_Imaginary
unsigned
char
float
double
 

scanf() Specifiers

%c
character
%d
signed decimal integer
%e, %f, %g, %aC99
floati­ng-­point number
%E, %F, %G, %AC99
floati­ng-­point number
%i
signed decimal integer
%o
signed octal integer
%p
ponteran address
%s
string1
%u
unsigned decimal integer
%x, %X
signed hexade­cimal integer
1 begins with first non-wh­ite­space character and ends with the next whitespace character

printf() Specifiers

%a
floati­ng-­point number, hexade­cimal digit and P-nonation C99/C11
%A
floati­ng-­point number, hexade­cimal digit and P-nonation C99/C11
%c
single character
%d
signed decimal integer
%e
floati­ng-­point number, exponent is less than -4 or greater than or equal to the precision
%E
floati­ng-­point number, exponent is less than -4 or greater than or equal to the precision
%f
floati­ng-­point number, decimal notation
%g
use %f or %e, depending on the value
%G
use %f or %E, depending on value
%i
signed decimal integer same as %d
%o
unsigned octal integer
%p
pointer
%s
character string
%u
unsigned decimal integer
%x
unsigned hex integer, using hex digits 0f
%X
unsigned hex integer, using hex digits 0F
%%
prints a % sign