C Reference Cheat Sheet Page 6

ADVERTISEMENT

C Reference Cheat Sheet
by
Ashlyn Black
via
Condit​ i onal (Branc​ h ing)
Iterative (Looping) (cont)
if, else if, else
Loop keyword.
do
Evaluates b if a is true.
Loop delimiters.
if(a) b;
{}
Evaluates b and c if a is true.
Loop contents.
if(a){ b; c; }
c++;
Evaluates b if a is true, c
Loop keyword and condition parenthesis. Note
if(a){ b; }else{ c; }
while();
semicolon.
otherwise.
Test condition.
Evaluates b if a is true,
c != 'Z'
if(a){ b; }else if(c){ d;
otherwise d if c is true,
}else{ e; }
for
otherwise e.
int i; for(i = 0; n[i] != '\0'; i++){} (C89)
switch, case, break
OR
Evaluates c if a equals b.
switch(a){ case b: c; }
for(int i = 0; n[i] != '\0'; i++){} (C99+)
Evaluates b if a matches no
switch(a){ default: b; }
Compact increment/decrement based loop.
other case.
Declares integer i.
int i;
Evaluates d if a equals either b
switch(a){ case b: case c:
Loop keyword.
for()
or c.
d; }
Initialises integer i. Semicolon.
i = 0;
Evaluates c, e and f if a equals
switch(a){ case b: c; case
Test condition. Semicolon.
b, e and f if a equals d,
n[i] !=
d: e; default: f; }
otherwise f.
'\0';
Increments i. No semicolon.
Evaluates c if a equals b, e if a
i++
switch(a){ case b: c; break;
equals d and e otherwise.
case d: e; break; default: f;
Loop delimiters.
{}
}
continue
int i=0; while(i<10){ i++; continue; i--;}
Iterative (Looping)
Skips rest of loop contents and restarts at the beginning of the loop.
while
break
int x = 0; while(x < 10){ x += 2; }
int i=0; while(1){ if(x==10){break;} i++; }
Loop skipped if test condition initially false.
Skips rest of loop contents and exits loop.
Declare and initialise integer x.
int x = 0;
Loop keyword and condition parenthesis.
while()
Console Input/​ O utput
Test condition.
x < 10
#include <stdio.h>
Loop delimiters.
{}
Characters
Loop contents.
x += 2;
Returns a single character's ANSI code from the input
getchar()
stream buffer as an integer. (safe)
do while
Prints a single character from an ANSI code integer to
putchar(int)
char c = 'A'; do { c++; } while(c != 'Z');
the output stream buffer.
Always runs through loop at least once.
Strings
Declare and initialise character c.
char c = 'A';
By Ashlyn Black
Published 28th January, 2015.
Sponsored by
Last updated 20th April, 2015.
Measure your website readability!
Page 6 of 13.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education