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.

Reading & exercisesΒΆ

(3-4h)

From p.138 to p. 174 including exercise 3.9.

Same procedure as How to read πŸ€“ from the last preparation, read, go through the points below and note down your doubts, and share them in discussions πŸ“€πŸ‘₯.

  • 3.2 Algorithms

    • algorithm

  • 3.3 Pseudocode

    • pseudocode

    • pseudocode vs flowchart?

    • Why is int i usually not part of the pseudocode?

  • 3.4 Control structures

    • sequential execution, transfer of control -- how do these compare to the Big 3 table?

    • goto statement (avoided in structured program development)

    • structured programming and goto elimination[1]

    • single-entry/single-exit control statements

    • control statement stacking

    • selection statements

      • single selection if

      • double selection if-else

      • multiple selection switch (introduced in chapter 4)

    • iteration statements in C

      • (pre-test loop) while

      • (post-test loop) do-while (introduced in chapter 4)

      • (pre-test loop with counter) for (introduced in chapter 4)

  • 3.5 if selection statement

    • if structure (in flowchart)

    • indentation (white spaces) when using if

  • 3.6 if..else selection statement

    • if..else structure (in flowchart)

    • conditional expression

      • the ternary operator ? :

    • nested if..else statements[2]

    • compound statement or block { }

    • Error types

      • syntax

      • execution time (fatal, non-fatal)

  • 3.7 while iteration statement

    • while structure (in flowchart)

    • infinite loop πŸ’€

  • 3.8 Formulating algorithms: Stepwise refinement 1: Counter-controlled iteration

    • counter-controlled (or definite) iteration

    • garbage value (uninitialized variable)

    • %s conversion specifier for strings (introduced first in section 2.7)

  • 3.9 Stepwise refinement case study 2: sentinel-controlled iteration

    • sentinel values

    • top-down refinement (compare it with beginning a flowchart with a single process and then converting it into multiple processes)

    • program phases: initialization, processing, termination

    • converting between types

      • cast operator (type)

      • explicit double avg = (double) sum / count; (if sum and count are int)

      • implicit double avg = sum / count;

    • floating point number formatting ("%.2f\n")

    • productivity: pseudocode, flowchart vs writing C code

  • 3.10 Stepwise refinement case study 3: Nested control statements

    • nesting an if into a while (while there are students to process, increment the number of passed students if ...)

  • 3.11 Assignment operators

    • +=, -=, *=, /=, %= πŸ†’

  • 3.12 Increment and decrement operators

    • increment ++ and decrement -- operators 😎

    • pre-increment ++i vs post-increment i++

  • (optional) 3.13 Secure C programming πŸ›‘οΈ

    • Arithmetic overflow

    • INT_MAX and INT_MIN from <limits.h>

    • scanf_s and printf_s

    Supplementary: One of the exercises that we will cover in the lecture (similar to 3.18) requires reading doubles, but the chapter does not cover it: `scanf(β€œ%lf”, ...)

FootnotesΒΆ
  1. The right one is shorthand for the left one, and is more readable:

    if (c1) {
      ;
    } else {
      if (c2) {
          ;
      } else {
          ;               
      }
    }
    if (c1) {
      ;
    } else if (c2) {
      ;
    } else {
      ;
    }