7/20/2020 Beginning C Programming For Dummies Cheat Sheet
Beginning C Programming For
 Dummies Cheat Sheet
 From Beginning Programming with C For Dummies
 By Dan Gookin
 The best way to learn programming is to start with a fundamental language like C.
 Nearly every other popular language today borrows from C. Whether you’re
 curious about programming, need to pass a college course, or want to start your
 own app business, learning C is the right place to begin.
 Understanding the C Language Skeleton
 Most coding starts with a C language structure. This skeleton includes the basic
 bones upon which most programs are written. Use this simple skeleton to get
 started:
 #include <stdio.h>
 int main()
 {
 return(0);
 }
 Traditionally, the program begins with preprocessor directives plus prototypes.
 The #include statements bring in header files, such as stdio.h, the standard
 input/output header file.
 The primary function in all C code is main(), which is the first function that’s run
 when the program starts. The main() function is an int function, so it must return
 an integer value. All the function’s statements are enclosed in curly brackets, or
 braces.
 C Language Keywords
 The C language keywords represent the core of the language. With the C11
 revision to the language, several new keywords have been added. They’re shown
 with leading underscores in the following table:
 _Alignas break float signed
read://https_www.dummies.com/?url=https%3A%2F%2Fwww.dummies.com%2Fprogramming%2Fc%2Fbeginning-c-programming-for-dummies-c… 1/5
7/20/2020 Beginning C Programming For Dummies Cheat Sheet
 _Alignof case for sizeof
 _Atomic char goto static
 _Bool const if struct
 _Complex continue inline switch
 _Generic default int typedef
 _Imaginary do long union
 _Noreturn double register unsigned
 _Static_assert else restrict void
 _Thread_local enum return volatile
 auto extern short while
 Keep the following points in mind as you start programming in C:
 Do not name any function or variable the same as a keyword.
 You use only a few of the C language keywords in your code. Some of
 them, you’ll probably never use.
 Most of the work in your code is done by functions, not by keywords.
 C Language Variable Types
 Rather than make all your variables floats, it’s more efficient to examine the type
 of data that’s stored and then choose an appropriate C variable type.
 Type Value Range
 _Bool 0 to 1
 char –28 to 127
 unsigned char 0 to255
 short int –32,768 to 32,767
 unsigned short int 0 to 65,535
 int –2,147,483,648 to 2,147,483,647
 unsigned int 0 to 4,294,967,295
 long int –2,147,483,648 to 2,147,483,647
 unsigned long int 0 to 4,294,967,295
 float 1.17×10–38 to 3.40×1038
 double 2.22×10–308 to 1.79×10308
 Keep these C language variable type points in mind:
read://https_www.dummies.com/?url=https%3A%2F%2Fwww.dummies.com%2Fprogramming%2Fc%2Fbeginning-c-programming-for-dummies-c… 2/5
7/20/2020 Beginning C Programming For Dummies Cheat Sheet
 Ensure that you choose the proper variable type for the values you
 need to store.
 The _Bool type stores only two values, 0 and 1, which can represent
 TRUE or FALSE or On or Off or any binary condition.
 The char variable type stores character values, though it can also be
 used to store tiny integers.
 Integers, or whole numbers, are stored in the int variable types.
 Any type of value, from the very large to the very small, and any
 fractional values are stored in the float and double types.
 Remember to use int values for functions that generate integers, such
 as getchar(). It’s easy to assume that the function returns a char value
 because of the function’s name.
 C lacks a string variable type. Instead, an array of char variables is
 used.
 Other variable types include structures and pointers.
 Common C Escape Sequences
 When you cannot type characters into your string, use the escape sequences to
 insert nonprintable characters into text strings, char variables, and arrays. Here are
 common C escape sequences:
 Characters What It Represents or Displays
 a Bell (“beep!”)
 b Backspace, non-erasing
 f Form feed or clear the screen
 n Newline
 r Carriage return
 t Tab
 v Vertical tab
 \ Backslash character
 ? Question mark
 ‘ Single quote
 “
read://https_www.dummies.com/?url=https%3A%2F%2Fwww.dummies.com%2Fprogramming%2Fc%2Fbeginning-c-programming-for-dummies-c… 3/5
7/20/2020 Beginning C Programming For Dummies Cheat Sheet
 Common C Conversion Characters
 The printf() and scanf() functions use conversion characters as placeholders for
 various values. Conversion characters are used to indicate a value when the
 function runs in the final program.
 Conversion
 What It Displays
 Character
 %% The percent character (%)
 %c A single character (char)
 %d Integer value (short, int)
 Floating-point value in scientific notation using a little E
 %e
 (float, double)
 Floating-point value in scientific notation using a big E
 %E
 (float, double)
 %f Floating-point value in decimal notation (float, double)
 Substitutes %f or %e, whichever is shorter (float,
 %g
 double)
 Substitutes %f or %E, whichever is shorter (float,
 %G
 double)
 %i Integer value (short, int)
 %ld Long integer value (long int)
 %o Unsigned octal value, no leading zero
 %p Memory location in hexadecimal (*pointer)
 %s String (char *)
 Unsigned integer (unsigned short, unsigned int, unsigned
 %u
 long)
 Unsigned hexadecimal value, lower case (short, int,
 %x
 long)
 Unsigned hexadecimal value, capital letters (short, int
 %X
 long)
 The Order of Precedence in C
 The order of precedence determines which operators act upon a value first. When
 crafting statements, know the order of precedence to ensure that the program does
 what you intend.
 Operator(s) Category Description
read://https_www.dummies.com/?url=https%3A%2F%2Fwww.dummies.com%2Fprogramming%2Fc%2Fbeginning-c-programming-for-dummies-c… 4/5
7/20/2020 Beginning C Programming For Dummies Cheat Sheet
 ! Unary Logical not; associativity goes right to left
 ++ — Unary Increment, decrement, read from right to left
 */% Math Multiplication, division, modulo
 +– Math Addition, subtraction
 << >> Binary Shift left, shift right
 Less than, greater than, less than or equal to, greater
 < > <= >= Comparison than or
 equal to
 == != Comparison Is equal to, not equal to
 & Binary And
 ^ Binary Exclusive or (XOR)
 | Binary Or
 && Logical And
 || Logical Or
 ?: Comparison Weird if thing; associativity goes right to left
 Variable assignment operator, including the +=, *=,
 = Assignment and all
 assignment operators
 The comma separates items in a for
 , (None)
 statement; precedence from left to right
 The order of precedence can be overridden by using parentheses. Simply enclose
 within a set of parentheses the part of the equation that you want executed first.
 That part is executed first no matter what the priority is.
read://https_www.dummies.com/?url=https%3A%2F%2Fwww.dummies.com%2Fprogramming%2Fc%2Fbeginning-c-programming-for-dummies-c… 5/5