Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

GitHub Education Benefits Application

(10m)

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 for iteration

    • syntax

    • 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 switch multiple-selection

    • syntax

    • flowchart

    • reading character input (grade = getchar()) != EOF

    • assignments have values a = b = 0

    • EOF, Ctrl + d on Linux/macOS, Ctrl + z on Windows

    • controlling expression

    • default

    • limitation: each case can test only a constant integral expression

    • Notes on Integrat types: There are also datatypes like short int (short), unsigned int (unsigned), long int etc.

      • Recommendation: use int unless you need need the range of unsigned.

  • 4.7 do-while

    • syntax

    • flowchart

    • ⚠️prof: do-while is 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, continue

    • some argue that these break the rules of structured programming

    • result in simple code and better performance

  • 4.9 Logical operators

    • && and

    • || or

    • ! not

    • precedence && > ||

    • short-circuit evaluation a == 1 && b > 42

    • ⚠️prof: instead of _Bool and stdbool.h use directly bool in C23 (the standard that our template uses)

  • 4.10 Confusing equality vs assignment operators ==, =

    • lvalues vs rvalues

    • using 7 == x against assignment

    • constants 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 if if-else switch, three iterations while do..while for

    • stacking rule

    • nesting rule

    • three forms of control (#big3)

  • 4.12 Secure C programming

    • return value of scanf

    • range checking after scanf