Intro
C: Study Guide
This
guide does not include topic
detail
Operators
Arithmetic:
+ - * / (integer and float) %
Assignment:
=
Compound
assignment:
+= -=
*= /= %=
Increment/Decrement:
++ --(prefix
and postfix)
Indirection/dereference:
*
Address: &
sizeof
cast
Relational
>=
>
<= <
!= ==
Logical
!
&& ||
Precedence and associativity
Concepts
of programming
Structured
programming: 3 basic control structures (sequence, including fn
calls, selection, repetition)
Top-down
design
Stepwise
refinement (factoring, decomposition, modularization)
Benefits
of using functions
Ease
of maintenance: small problems easier to code, debug, maintain than
large
Reusability
once written and
debugged, just use
if have to modify, only
need to change in one place
rather than
hunting down duplicate code
reuse in same program or make generic libraries
Data
protection
Miscellaneous fn topics
Structure chart
IPO chart
Local
vs. global variables
Calling
vs. called functions
Builtin vs.
user-defined functions
Boolean
functions
Input
vs. output parameters
Formal
vs. actual parameters
Communication
between functions done with parameters and return values
fn can take 0 or more
parameters
fn can return 0 or 1
value only
Pass-by-value
vs. pass-by-reference
How to use each
Why to use each
Rules
of thumb regarding output param
vs. return value
Math
functions
#include
<math.h>
as well as -lm compile option
Random
number generation (pseudo)
Seeding the PNG with
constant or system time
Generating random number
range of random numbers
scaling and shifting
Math
functions
sqrt, pow
compile with
–lm option
Selection
if, if-else, if-elseif
(coding style seen as if-else
by compiler)
Flowchart diagrams
DeMorgan's law
Avoid coding the negative
No null if or else statements
if null if, make if (!cond)
and have body of else be body of if
if null else, simply eliminate: an if
doesn't need an else
Nested if
Dangling else
Iteration
finite vs. infinite loops
pretest vs. posttest loops
status-controlled vs. counter-controlled loops
Flowchart
diagrams
loop
initialization, control, process, update
while
for
do-while
nested loops
jump statements
break: only acceptable in switch
statement
continue: not acceptable
return: only acceptable once
sequentially at end of function
goto:
not acceptable
Character
processing
EOF
getchar(), putchar()
while ((cInput = getchar())
!= EOF)
Builtin
character-processing Boolean functions
isalpha
isupper
islower
isdigit
ispunct
isspace
Builtin
character conversion functions
toupper
tolower
Return value of each must be captured or somehow used
Data
validation
f/scanf()
return value of EOF or number of successful conversions
Files
file streams
fopen(), fclose()
fprintf(), fscanf()
fgetc(), fputc()
FILE *, NULL
stdin, stdout, stderr
Recursion
why to use in place of iteration
infinite recursion
base case(s)
recursive case(s)
requirements for writing recursive function
control parameter
base case(s), recursive case(s)
return value if calculating
Factorial,
Fibonacci, print countdown
Arrays
homogeneous collection of data stored contiguously in memory and indexible
by same name and
subscript
1D, 2D, multiD
scalar variable
indices 0 to n-1 for size n
array name is address
use #define for array size references for ease of maintenance
declaration, initialization, accessing elements
[] index operator
process with for loop
boundaries are programmer's responsibility
passing arrays to functions (PBR), passing 1 row of 2D (PBR), passing 1
element
(PBV)
why is it necessary to specify column size when passing 2D array to
function
data type and actual memory address of row or element given starting
address,
array declaration, and subscripts