Week 1 C

C. Source Code. Machine Code. Compiler. Correctness, Design, Style. Visual Studio Code. Syntax Highlighting. Escape Sequences. Header Files. Libraries. Manual Pages. Types. Conditionals. Variables. Loops. Linux. Graphical User Interface (GUI). Command-Line Interface (CLI). Constants. Comments. Pseudocode. Operators. Integer Overflow. Floating-Point Imprecision.

Erratum

When we introduced the “do-while loop” toward the end of lecture, in our final version of mario.c, I’m afraid I typed this:

do
{
    int n = get_int("Size: ");
}
while (n < 1);

I then claimed that n would still be considered “in scope” in the Boolean expression on that last line. Afraid I should have literally said the opposite. (Since it’s not!) I should have typed:

int n;
do
{
    n = get_int("Size: ");
}
while (n < 1);

thereby “declaring” (i.e., creating) n outside of the loop’s curly braces so that it would be “in scope” both inside the curly braces and inside of the Boolean expression, thereby allowing me to assign (and even reassign) it a value as well as check whether its value is less than 1.

See github.com/cs50/lectures/blob/2023/fall/1/src1/mario7.c#L9-L14 for the complete program.

Apologies for the confusion!