Lecture 3: C basics pt. 2

Today, we continue learning some basic C programming concepts.

Functions

video

Optional reading: chapter 3.1-3.5

Key ideas:

  • Use functions to organize your program and to reuse code
  • Input (one or multiple) and output (only one) of functions

Relational, equality, and logical operators

video

Key ideas:

  • relational (>, <, >=, <=) and equality operators (==, !=, !)
  • logical operators (&&, ||)
  • writing conditions in C: to write that x is in the range -9 to 99, we need to say
    x > 10 && x < 100
    

    not -10 < x < 100.

  • operator precedence: https://devdocs.io/c/language/operator_precedence

Optional reading: chapter 4.1-4.2

if statements

video

Key ideas:

  • Single alternative or multiple alternative
  • Nested if statements

Optional reading: chapter 4.3

switch statements

video

Key ideas:

  • Alternative to if statements to select one of many alternatives
  • Only works with char and int data types for controlling expression
  • Must include break statement for each alternative

Optional reading: chapter 4.8

Lab 1 intro

video