Python Memory Management and Tips Transcripts
Chapter: Python variables and memory
Lecture: Passing values in C

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's look at one more example before we move on to talk about how Python does
0:04 the equivalent thing. So let's look at a slight variation.
0:07 We've got the same SamePerson function.
0:11 It's going to take two people and determine if they're the same.
0:14 However, this time, instead of passing pointers,
0:16 which are basically numbers to memory addresses where the real data lives,
0:20 we're just gonna pass the id's.
0:21 Remember before we're saying p1 arrow,
0:24 id. Might as well
0:25 just past the id that makes it a little easier to do.
0:28 So we have our two pieces of data
0:31 which are integers p1_id and p2_id.
0:33 They don't point anywhere. They literally just have the value,
0:37 right? This is the same thing that was the id before.
0:40 So in C, we can pass the value of a thing or we can pass
0:44 a pointer like we saw before and there's good reason for both.
0:48 If you have a large data structure and you want to move it around without making copies
0:52 because that would be slow,
0:54 You would pass by reference or pass a pointer. If you wanted to,
0:58 even more importantly, you want to make changes to it and have those changes reflected
1:02 in other parts of the program,
1:03 you need to pass the pointer, change the shared location,
1:07 and then everyone will see those changes. As opposed to here
1:10 if we change the id
1:11 only this function would see it.
1:13 But, C and many languages, c#,
1:15 other languages, they have this distinction between passing sometimes just the value,
1:20 like the integers, and sometimes
1:22 like previously the address of the thing that you gotta follow as a pointer out there.
1:27 So, I want to put these two up and contrast them for you,
1:30 and then we're gonna dive into Python.