GitHub Education Benefits Application¶
(10m)
Go to Education benefits and Start an application, to have free access to the tools we will use.
Reading & exercises¶
Similar to previous preparation.
(3-4h) Study Chapter 4 including exercise 4.8 p.224
4.2 Iteration
sentinel-controlled
counter-controlled
control variable
4.3 Counter-controlled iteration
name, initial value, iteration condition, increment or decrement
using integers vs doubles as the iteration variable
4.4
foriterationsyntax
flowchart
life-time of the iteration variable/s
off-by-one error
iteration variable used in the body
4.5 Examples
different increments
compound-interest calculation for subsequent years
floating-point representational errors
4.6
switchmultiple-selectionsyntax
flowchart
reading character input
(grade = getchar()) != EOFassignments have values
a = b = 0EOF, Ctrl + d on Linux/macOS, Ctrl + z on Windowscontrolling expression
defaultlimitation: each
casecan test only a constant integral expressionNotes on Integrat types: There are also datatypes like
short int(short),unsigned int(unsigned),long intetc.Recommendation: use
intunless you need need the range ofunsigned.
4.7
do-whilesyntax
flowchart
⚠️prof:
do-whileis better for iterations where the sentinel is the data that we need to get in each iteration. For example EV charger earning calculator
4.8
break,continuesome argue that these break the rules of structured programming
result in simple code and better performance
4.9 Logical operators
&&and||or!notprecedence
&&>||short-circuit evaluation
a == 1 && b > 42⚠️prof: instead of
_Boolandstdbool.huse directlyboolin C23 (the standard that our template uses)
4.10 Confusing equality vs assignment operators
==,=lvalues vs rvalues
using
7 == xagainst assignmentconstants can be only rvalues in an assignment statement
confusing
==vs=in standalone statements, e.g.,x == 1(luckily a modern language server warns about this.)
4.11 structured programming summary
flowcharts for sequence, three selections
ifif-elseswitch, three iterationswhiledo..whileforstacking rule
nesting rule
three forms of control (#big3)
4.12 Secure C programming
return value of
scanfrange checking after
scanf