Professional Documents
Culture Documents
Last Time
Pointer Caveats
Parameter Passing and Pointers
Sharing Info between Functions
Command Line Arguments
Today
Return Values and Pointers (from last time)
Parameter and Return Value Caveats (from last time)
Structures
Nested structs and Arrays of structs
Pointers to structs
Next Time
Read: K&R Ch. 7
Console & File I/O
C Strings
CS 354 (F16): L6 - 1
Structures
What?
Why?
How?
struct <struct-name> {
<data-declarations>;
} <optional-list-of-variables>;
Declare a structure representing a date having a integer.month, day of month, and year.
Typedef
what:
why:
CS 354 (F16): L6 - 2
pm) {
Name
Type
Weight
Caught on
:
:
:
:
%s",pm.name);
%s",pm.type);
%f",pm.weight);
", printDate(pm.caught));
int main(void) {
Pokemon pm1 = {"Abra","Psychic",30,{19,9,2016}};
printPm(pm1);
CS 354 (F16): L6 - 3
Pointers to structs
Why?
How?
Declare a pointer.
Update the code on the previous page to efficiently pass and print a pokedex,.
CS 354 (F16): L6 - 4