week 6 part 2 kyle dewey. overview array application: sorting basic structs ta evaluations
TRANSCRIPT
![Page 1: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/1.jpg)
Week 6 Part 2Kyle Dewey
![Page 2: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/2.jpg)
Overview
•Array application: sorting
•Basic structs
•TA Evaluations
![Page 3: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/3.jpg)
Sorting
![Page 4: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/4.jpg)
Sorting
•Given some list of items in any given order, put them in sorted order
•List of numbers ordered by <=
•List of words in lexicographic order
•List of plane flights in order by cost
![Page 5: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/5.jpg)
Sorting
•5, 3, 7, 2: (by <=)
•2, 3, 5, 7
•5, 3, 7, 2: (by >=)
•7, 5, 3, 2
•“moo”, “cow”, “bull” (lexicographic)
•“bull”, “cow”, “moo”
![Page 6: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/6.jpg)
Sorting Hard Drives
Maker Capacity Price RatingWarrant
y
Seagate 500 GB $80 4 / 5 3 years
Seagate 500 GB $150 5 / 5 5 years
Hitachi 750 GB $75 2 / 5 1 year
![Page 7: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/7.jpg)
The Point
•The same items can have different ways of being compared
![Page 8: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/8.jpg)
Thought Exercise
•Given a bunch of integers, devise 3 unique ways to sort them by <= (no code!)
•If they end up being sorted in the end, the method is valid
6 2 4 1 0 9 7
![Page 9: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/9.jpg)
Relevance to Us
•A lot of work has gone into sorting things
•Wikipedia page on sorting: 33 different methods
•There are more
•Some generally more efficient than others, some more efficient given data that looks a certain way (such as “nearly sorted”)
![Page 10: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/10.jpg)
Relevance to C
•There is a good chunk of code that goes into even the simpler ones
•Usually involve lots of array operations
6 2 4 1 0 9 7
![Page 11: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/11.jpg)
Selection Sort
•Basic idea: in an array of length N...
•Find the minimal element and swap it so that it’s in position 0
•Then, from position 1 and on, find the minimal element and replace it so it’s in position 1
•Keep doing this
![Page 12: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/12.jpg)
Selection Sort
6 2 4 1 0 9 7
Swap Min
Recorded Minimum Position: 0Recorded Minimum: 6
0 1 2 3 4 5 6
![Page 13: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/13.jpg)
Selection Sort
6 2 4 1 0 9 7
Swap Min
Recorded Minimum Position: 1Recorded Minimum: 2
0 1 2 3 4 5 6
![Page 14: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/14.jpg)
Selection Sort
6 2 4 1 0 9 7
Swap Min
Recorded Minimum Position: 1Recorded Minimum: 2
0 1 2 3 4 5 6
![Page 15: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/15.jpg)
Selection Sort
6 2 4 1 0 9 7
Swap Min
Recorded Minimum Position: 3Recorded Minimum: 1
0 1 2 3 4 5 6
![Page 16: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/16.jpg)
Selection Sort
6 2 4 1 0 9 7
Swap Min
Recorded Minimum Position: 4Recorded Minimum: 0
0 1 2 3 4 5 6
![Page 17: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/17.jpg)
Selection Sort
6 2 4 1 0 9 7
Swap Min
Recorded Minimum Position: 4Recorded Minimum: 0
0 1 2 3 4 5 6
![Page 18: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/18.jpg)
Selection Sort
6 2 4 1 0 9 7
Swap Min
Recorded Minimum Position: 4Recorded Minimum: 0
0 1 2 3 4 5 6
![Page 19: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/19.jpg)
Selection Sort
0 2 4 1 6 9 7
Swap Min
Recorded Minimum Position: 4Recorded Minimum: 0
0 1 2 3 4 5 6
![Page 20: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/20.jpg)
Selection Sort
0 2 4 1 6 9 7
Swap Min
Recorded Minimum Position: 1Recorded Minimum: 2
0 1 2 3 4 5 6
![Page 21: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/21.jpg)
Selection Sort
0 2 4 1 6 9 7
Recorded Minimum Position: 1Recorded Minimum: 2
0 1 2 3 4 5 6
Swap Min
![Page 22: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/22.jpg)
Selection Sort
0 2 4 1 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 1
0 1 2 3 4 5 6
Swap Min
![Page 23: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/23.jpg)
Selection Sort
0 2 4 1 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 1
0 1 2 3 4 5 6
Swap Min
![Page 24: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/24.jpg)
Selection Sort
0 2 4 1 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 1
0 1 2 3 4 5 6
Swap Min
![Page 25: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/25.jpg)
Selection Sort
0 2 4 1 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 1
0 1 2 3 4 5 6
Swap Min
![Page 26: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/26.jpg)
Selection Sort
0 1 4 2 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 1
0 1 2 3 4 5 6
Swap Min
![Page 27: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/27.jpg)
Selection Sort
0 1 4 2 6 9 7
Recorded Minimum Position: 2Recorded Minimum: 4
0 1 2 3 4 5 6
Swap Min
![Page 28: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/28.jpg)
Selection Sort
0 1 4 2 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 3
0 1 2 3 4 5 6
Swap Min
![Page 29: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/29.jpg)
Selection Sort
0 1 4 2 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 3
0 1 2 3 4 5 6
Swap Min
![Page 30: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/30.jpg)
Selection Sort
0 1 4 2 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 3
0 1 2 3 4 5 6
Swap Min
![Page 31: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/31.jpg)
Selection Sort
0 1 4 2 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 3
0 1 2 3 4 5 6
Swap Min
![Page 32: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/32.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 3
0 1 2 3 4 5 6
Swap Min
![Page 33: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/33.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 4
0 1 2 3 4 5 6
Swap Min
![Page 34: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/34.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 4
0 1 2 3 4 5 6
Swap Min
![Page 35: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/35.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 4
0 1 2 3 4 5 6
Swap Min
![Page 36: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/36.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 3Recorded Minimum: 4
0 1 2 3 4 5 6
Swap Min
![Page 37: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/37.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 4Recorded Minimum: 6
0 1 2 3 4 5 6
Swap Min
![Page 38: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/38.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 4Recorded Minimum: 6
0 1 2 3 4 5 6
Swap Min
![Page 39: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/39.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 4Recorded Minimum: 6
0 1 2 3 4 5 6
Swap Min
![Page 40: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/40.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 4Recorded Minimum: 6
0 1 2 3 4 5 6
Swap Min
![Page 41: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/41.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 5Recorded Minimum: 9
0 1 2 3 4 5 6
Swap Min
![Page 42: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/42.jpg)
Selection Sort
0 1 2 4 6 9 7
Recorded Minimum Position: 6Recorded Minimum: 7
0 1 2 3 4 5 6
Swap Min
![Page 43: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/43.jpg)
Selection Sort
0 1 2 4 6 7 9
Recorded Minimum Position: 6Recorded Minimum: 7
0 1 2 3 4 5 6
Swap Min
![Page 44: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/44.jpg)
Selection Sort
0 1 2 4 6 7 9
Recorded Minimum Position: 6Recorded Minimum: 9
0 1 2 3 4 5 6
Swap Min
![Page 45: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/45.jpg)
Selection Sort
0 1 2 4 6 7 9
Recorded Minimum Position: 6Recorded Minimum: 9
0 1 2 3 4 5 6
Swap Min
![Page 46: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/46.jpg)
Code
![Page 47: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/47.jpg)
Structs
![Page 48: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/48.jpg)
Problem
•We want to represent a phone book
•Each entry has:
•Name
•Phone number
•Address
![Page 49: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/49.jpg)
Question
•Which type(s) is/are appropriate for:
•Name?
•Phone Number?
•Address?
![Page 50: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/50.jpg)
Possible Representation
•Use parallel arrays
•Each array holds one kind of item
•Index N refers to all information for entry #N
char** name;char** address;int* phoneNumber;
![Page 51: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/51.jpg)
Problem
•Poor separation of concerns
•We have to pass around everything related to one person, which is annoying and error prone
void printPerson( char* name, char* address, int phone );
![Page 52: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/52.jpg)
Another Solution
•Use structures, aka. structs
•Put all data relevant to one entry in one place
struct person { char* name; char* address; int phone;};
![Page 53: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/53.jpg)
Structs
struct person { char* name; char* address; int phone;};
void printPerson( struct person p );
![Page 54: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/54.jpg)
Accessing Structs•Use the dot (.) operator
void printPerson( struct person p ) { printf( “Name: %s\n”, p.name ); printf( “Address: %s\n”, p.address ); printf( “Phone: %i\n”, p.phone );}
struct person { char* name; char* address; int phone;};
![Page 55: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/55.jpg)
Modifying Structs•The dot (.) operator can be used
along with assignmentstruct person { char* name; char* address; int phone;};struct person p;p.name = “foo”;p.address = “123 Fake Street”;p.phone = 0123456789
![Page 56: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/56.jpg)
Pointers to Structs
•Structs can also be accessed via pointers
•Can access like so:
struct person p;struct person* pointer = &p;(*p).name = “foo”;(*p).address = (*p).name;(*p).phone = 0123456789
![Page 57: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/57.jpg)
Pointers to Structs
•Structs can also be accessed via pointers
•Can also access with the more readable arrow operator
struct person p;struct person* pointer = &p;p->name = “foo”;p->address = p->name;p->phone = 0123456789
![Page 58: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/58.jpg)
More on Structs (Only if Time
Permits)
![Page 59: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/59.jpg)
Struct Semantics
•Consider again:
void printPerson( struct person p );
•When structs are passed, the whole thing is copied
•Note that this is a shallow copy
![Page 60: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/60.jpg)
Shallow Copystruct person { char* name; char* address; int phone;};
“Bob” “124 Fake Street”
9876543210namename addressaddress
phone
![Page 61: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/61.jpg)
Shallow Copy
“Bob” “124 Fake Street”
9876543210namename addressaddress
phone
9876543210
phone
namename addressaddress
![Page 62: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/62.jpg)
Questionstruct foo { int x;};void bar( struct foo f ) { f.x = 10;}int main() { struct foo f; f.x = 5; bar( f ); // what’s f.x? return 0;}
![Page 63: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/63.jpg)
Questionstruct foo { char* x;};void bar( struct foo f ) { f.x = “moo”;}int main() { struct foo f; f.x = “cow”; bar( f ); // what’s f.x? return 0;}
![Page 64: Week 6 Part 2 Kyle Dewey. Overview Array application: sorting Basic structs TA Evaluations](https://reader036.vdocuments.net/reader036/viewer/2022062408/56649f285503460f94c40263/html5/thumbnails/64.jpg)
Structs and Pointers
•Oftentimes programmers will prefer pointers to structs as opposed to just structs
•Avoids extra copying
•Possibly appropriate