diff options
author | loshprung <lshprung@scu.edu> | 2020-01-15 11:36:18 -0800 |
---|---|---|
committer | loshprung <lshprung@scu.edu> | 2020-01-15 11:36:18 -0800 |
commit | 7d3749d0141f62c0beda8284d74c84330ef04d72 (patch) | |
tree | 5674773abab356df7c13183155cb899d4ea242a2 | |
parent | 5c01ce58cb53df8a5cccd0b18b98f2135c191a29 (diff) |
Post-class 01/15
-rw-r--r-- | 01-15.md | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/01-15.md b/01-15.md new file mode 100644 index 0000000..bf362d1 --- /dev/null +++ b/01-15.md @@ -0,0 +1,83 @@ +[\<- Notes 01/13](01-13.md) + +--- + +Notes 01/15/2020 + +# Review Pointers + +Below is an example to demonstrate pointer precedence: + +``` +int x[] = {0, 5, 10, 15, 20, 25, ...}; +int y = 5; +int *p = x; + +y = ++*p +printf("%d, %d\n", y, *p); +y = *(++p); +printf(...); //ditto +y = ++(*p); +printf(...); //ditto +``` + +The code outputs the following: + +``` +1, 1 +5, 5 +6, 6 +``` +--- + +# Introduction to Structures in C + +-`Earlier we talked about data types: int, char +- A Structure allows for multiple data types in one array +- Structure Basics + - A structure is a collection of values, called members + +- Outline of Structure Definition: + +``` +struct name{ + variable declaration; + variable declaration; + ... +}; +``` + +- Example: + +``` +struct info{ + int number; + char character; + char string[10]; + int array[10]; +}; +``` + +- Let's see the memory: + +| | | +| - | - | +| | | +| Real_Info | 55 bytes of storage | +| | | + +- You can also create pointers to data structures + +- Defines a structure type + +--- + +- Another Example: + +``` +struct node{ + int number; + struct node *link; +}; +``` + |