Lecture 3: C basics pt. 2
Today, we continue learning some basic C programming concepts.
Functions
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
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 sayx > 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
Key ideas:
- Single alternative or multiple alternative
- Nested if statements
Optional reading: chapter 4.3
switch
statements
Key ideas:
- Alternative to
if
statements to select one of many alternatives - Only works with
char
andint
data types for controlling expression - Must include
break
statement for each alternative
Optional reading: chapter 4.8