CS1010 C Programming
C in CS1010
Banned in CS1010
- The
++
and--
operatorsUse
i += 1
ori -= 1
instead. - Skipping of curly braces for single statement conditional or loop body
Always use
{}
even if the conditional or loop body contains only a single statement. - Nested conditional operator
?:
Use nested
if-else
loop - Global variables
Declare the variables as local, automatic variables, and pass them around.
- Using
int
andshort
Always use
long
, which is guaranteed to be at least 32 bits. Exception: If a function from a C library calls for the use ofint
and offers nolong
alternative, then we have to useint
. - The type
float
Always use
double
- Using integer values for true/false
Use the
bool
type, and the valuestrue
andfalse
goto
Use combinations of conditionals and loops
Discouraged in CS1010
printf()
andscanf()
functionsUse the CS1010 I/O Library
switch
statementsUse
if-else
statementsbreak
andcontinue
statementsUse simple loops with a single entry and a single exit point. Use flag variables to indicate special conditions to exit or continue with the loop.
- Skipping parenthesis
Use parenthesis
The CS1010 I/O Library
Handbook is here.
C Style Guide
Handbook is here.