 Hello again, I'm here with my friend James, and I should have mentioned this in previous videos. I apologize if any background noise. We are outside at James's house, I traveled to get here, and I'm just using the camera mic because that's all I have right now. So for people who've probably complained on the previous videos, not much I can do. Sorry. I know it looks like a garden, but it's a noisy neighborhood. So as we mentioned in the past, I mean, you've done a lot of programming, you've worked for a web design company, you've done a lot of Java and other languages, but C is probably your favorite language. And I've played around with C. I can accomplish stuff. My code is probably horrible when I write it, but it gets the job done, and I just haven't put enough time into learning C. But years ago, I bought a book on programming, which I should never do, because it's always easier to just look up what I need to do online and figure it out. But I bought this book, and I'm reading through it, and I'm going, this is good. I'm learning C each chapter had a different topic, and then I got to the topic of pointers. And I'm halfway through this chapter, and I'm like, I don't know what's going on. I'm skipping this chapter. But every chapter after that had to do, referred back to the pointer chapter. And since then, I understand what pointers are and why we need them, not in great details. They don't use them often. I also find that when I talk to people who are big C people, which I think C is a great, great language, but they all seem to really, really want you to love pointers. I was talking with some of my IRC channel the other day, and I just mentioned how- Pointers will set you free. I was talking to someone, and I just mentioned that I understand the concept of pointers, but I don't use enough to really grasp everything about them. So he goes on explaining how they work, and I wasn't really looking for explanation, and I just started laughing, ha ha ha, LOL, whatever. I'm like, you remind me I'm a best friend, James. I go, how come is it every C person just wants you to love pointers? So why don't we start off, and why don't you just explain what a pointer is? So yeah, yeah. As a matter of fact, I'll go a step further, and I want to answer your question. Okay, that's great. I'll say that, like, yeah, so there are certain things in programming, certain obstacles that once you overcome, like you hit that zen moment, where you just feel like, oh, I understand things on a whole other level now. Whether this is a useful thing to ever use again, or not, then once I understand it, I kind of understand programming on a whole other level. And you know, if I could just plug some books, you know, obviously the C programming language by Carnegie and Richie, that's a very important book to learn C, Sick P was a lecture series that was very important in the laboratory I worked in. We're required reading, required to watch the free videos put out by MIT. Not real quick, the first book you mentioned, those are the guys who wrote the C programming language, and Richie even wrote, you know, came up with UNIX. He wanted to have an operating system, UNIX is what he envisioned, and so if I get this, if I get the story wrong, nobody will kill me. Right, and he passed away. I'm not a historian. Yeah, so he was the one that came up, he wanted the UNIX operating system, he had an idea what it would be like, and he needed a language to write it in, and he wrote it in C. But anyway, so yeah. And that's hardcore. Yeah, yeah. The only thing I want to write an operating system, I'm going to create my own language to write the operating system in that, and that's awesome. So, I think if you go through that book, and you run all those exercises, and exercises are kind of boring, it's much more fun to have a project. Right. So, if you run all those exercises, you should understand, not just pointers, but a whole array of ideas from C. And I like SICKP because you understand functional programming language, which is a very difficult concept. Is SICKP short for something? Structure and interpretation of... That's good enough. That's more than I know. ...structure of computer programming. Okay. Structure and interpretation of computer programming. Anyway, so once you understand how functional programming languages work, once you understand how pointers work, and some people might say object-oriented programming is very important to learn, but I just think that's a little bit easier of a concept for people to learn. So, you can learn that one on your own pretty easily, I think. But once you get those kind of concepts, each one of those kind of takes you to another level. So, that's why I think I would be a pointer aficionado, and I would preach it, because once you understand pointers, you understand something about how that computer works, especially a Unix operating system to a whole other level. Now, to answer your question, your question was basically how do pointers work. Yeah, what are they? Now, it's because most languages, the higher level languages that are written in C are written to handle the pointers for you. Right. So, I don't have much experience with them because those are the languages I usually use for pointers. And then there's another way to look at that. You could say, instead of thinking about pointers, another thing is just allocation of data. Like, how does a computer know how much memory to allocate for all the data you're looking at? And so, for C, generally, it's not an assembly language where you have to explicitly say where to put every single bit of data. But it's kind of left to the user to start allocating and deallocating memory. And if the user doesn't do it right, you can actually have things like memory leaks where you're not freeing up memory and all of a sudden your computer has no memory. Or conversely, you could start trying to access memory that was not actually allocated, try to put something in memory that wasn't allocated, and you get the seg fault, which in C, it's really hard to figure out where did that seg fault come from. Quick thing, which will probably be a whole other video, but real popular right now, although this video will be released later on, the whole heart bleep thing. Sure, yeah. Oh, yeah. Which does not get into that, but that is probably from the little bit I've read about it. Yeah, that's an example of... Cherry memory that shouldn't be... The block of memory is somehow you can use a C program that's been written because it's so low level, so at the level of the operating system that it basically has access to all the memory and you're supposed to be writing it so that you're limiting the access. But if you wrote it incorrectly, all of a sudden you're able to kind of glean some information off the edges of what you're supposed to be using it for. And really when I write stuff in C, which is really, really basic, basic stuff mostly, really I always have a fear of my background in the back of my head that I'm going to write something, which I've mentioned to you because pretty much I write something in C and I send it to you because not only so you can show me a better way of doing it, but also because I'm always worried that not that I've written anything that I've shared with the public, because all of that stuff I've done for my own personal use, but I'm just afraid that I'm going to leak something that I shouldn't, but with simple projects that's less of a concern. Sure, yeah. Because really in the stuff I write I really haven't really done too much deep with pointers other than storing variables. Yeah. And so I mean part of the beauty of C is you get to control that stuff and so there's advantages to that and again for the learning process it's very good. But then most other programming language have, I'm sure you heard the term garbage in, garbage out. And so based on how you write... That's about nutrition when you eat. Yeah, yeah. So the idea is that how you write the programming language it will actually automatically wrap that for you. It will abstract it away from you and handle those things for you. And where in C they don't, you're supposed to build those abstracted layers for yourself. So yeah, I mean there is a little bit of danger in it, but you know that's the fun, right? Yeah, that's why you want to play with pointers because if you couldn't break something it wouldn't be fun. Right, right. I mean that's programming. That's what computers in general. If you haven't broken your system lately you haven't learned anything. Yeah, absolutely. So yeah, so use pointers, they're fun. You know how they work is, I mean I think the best, when I had my first aha moment with pointers is I started calling them addresses. I thought it was a much better way to think about a pointer. You know, yeah, you can think of it, well it's something that points to a memory address, but I think of it as an address. So it gets really complicated in C because when you start saying, well I pass a pointer to a function, what does that mean? Well in C when you pass something to a function it makes a copy of that data in that function. So you can't actually affect it outside the scope of the function unless you pass the pointer because you're essentially passing the address. And now you can affect what's at the address. You can't change the address, but you can affect what's at the address. Now is this, is that? No, never mind, I was going to say. I was going to say something. What did that burn out? Put this here. It might be. What I was about to say could have been very informative or sounded really, really stupid. So I'm not going to say. Leave that bonus footage. So real quick because we only have about a minute left. Yes. You tell the pointer, I wanted to point to this block of memory. How does it know that this block of memory is free to use? Yeah, well typically you're not going to point the pointer anywhere. There's different ways to access the pointer. Either you'll have a variable and you'll want to grab the pointer to it or sometimes you'll start with the pointer but generally the first thing the pointer is going to equal to the thing it's going to point to is it's something being returned from a malloc function. A malloc function or calloc or whatever function it is that does the allocation is going to return an address. Let me use the term address. It makes it easier. So you make an address variable. You set it equal to a function that returns an address. Now you have an address of allocated memory. When you're done with that, what you need to do since you manually allocated it, when you're done you need to free it. You're going to pass that same address to the free function and the free function will free the memory at that address. Great. Well, I thank you for joining me today. I thank you guys for watching. Please visit my website filmsbychris.com. That's Chris of the K. There should be a link in the description of this video if you're watching it on YouTube. And I'm really enjoying this conversation on C so I think our next talk will basically be a continuation of this one. So have a great day. But what I think really is a testament to your experience. When you have man-mind abilities, you run out of money. You run out of software. And it has creative effects. I think it says something about this.