Hi Aleksei, I may do a C++ series next year, it depends, there are already a lot of resources available, but I have been considering doing a short run of "Back To Basics" videos
@@javidx9 hey dude, really appreciate you sharing the delicate yet easy to understand explanation on such a crucial topic. please make the "back to basics" video :)
This guy is a genius, he is gentle, and wants everyone to learn at their own pace and on their own terms. He explains things like a gentleman and holds no judgement or arrogance towards others. He is in fact a PhD holder in Computer Science, as well as an experienced professional in the real world. It does not get any higher for anyone. He is undoubtable worth his weight in gold. Creative minds like this belong on the edge of technology and business
I've seen 4+ c++ pointer tutorials, and this one is the best one. You managed to explain the basics really well. I hope you will find time to make more videos covering the basics of c++
Thanks Kamil! I'm thinking about doing some sort of "C++ Basics" series, but there are a lot of resources already out there. I'll keep thinking about it though for the new year.
I was understanding everything (kinda) until 21:15, after that I lost track of what you were doing, I need to rewatch this many times but this is pure gold, I would like to express my deepest thanks to you for taking almost an hour of your life to share this super useful knowledge.
21 hours later, 13 skull fractures form banging your head in your desk and wall, mid level brain damage from drinking 92 redbulls, damaged vocal cords from screaming at your screen and your eyes in a constant clash between dryness from looking at a screen for so long and wetness from the pool of tears your formed before your tear ducts where completely empty, you understand the advanced parts if pointers.
Awesome video. Usually an explanation of pointers is just the first minute of this, and an assertion that they're really straightforward. Never usually go further and actually deal with how they can be confusing. Thank you!
I watched this once, and I'll watch this even twice or thrice or whatever it takes to thoroughly understand what's going on here. This is one of the best educative videos I've ever seen. I think it'll take me weeks of playing and experimenting with code to figure out the complexity of this stuff. Thank you very much!
This is one of the absolute best videos on the internet regarding pointer fundamentals. I recommend this to people who are new to the language any time I see them struggling to really grasp what pointers are and how they work. One thing I do wish you had gone over in this video (and would perhaps be a good topic for a supplementary video) is the differences between taking parameters by value, by reference, by pointer, by pointer to pointer, and by reference to pointer which I find to be the most common 4 ways to pass values into functions. For instance, when you start needing to develop application layers that are doing low level operations (like pointer arithmetic on a byte buffer), it can be very easy to make mistakes like not realizing that you need to either return a modified pointer from the function so that you can use the updated memory address externally or take a reference or pointer to a pointer as the parameter type. Also, I like your bit about smart pointers at the end, however, I think a good rule of thumb is that smart pointers are useful when they are being used how they were intended to be used, which is to denote ownership and not just "because it's modern". In otherwords if this is a low level piece of code that needs to be closely managed and optimized, like designing a custom data structure like an Octree implementation, then it is not a good idea to use smart pointers. If however, you are working on systems within an API where you need to denote "has-a" relationship component ownership of difference objects, then having unique and shared pointers can be useful and appropriate there.
Instantly liked after the definition of a pointer without a prompt. Also, I've been inexplicably drawn to C++ since I was a teenager, but couldn't quite start learning it, but now there's a huge UA-cam library, so what better time to start learning.
Note to myself: What I’ve learned from this video. Pointers are variables that hold memory addresses. You need to specify what datatype the pointer points to. A pointer of int can’t point to a double. A pointer of int can point to a memory address that stores an int value. Pointers are used in polymorphism to point from a base class to a derived class and have different types of objects (which all have one thing in common, they’re derived from the base class) this means it’s valid for an array or a vector to store both the base class object and derived class object in the same container and treats them as all the same. Thanks so much!
"The name of the array is a pointer" which I remember from other lessons. When the "*" is used to request the value of some pointer variable is called "dereference" as far as I understood it. int a = 5; int* b = &a; cout
UA-cam was on Auto Play mode and suddenly this video came up. I'm so happy that I didn't skip. This is by far the best introduction I've ever got into pointers. So far, no book was able to teach me what you did in a couple of minutes. And +1 for the Chrome joke :D Edit: I forgot to say thank you. So: Thank you!
I'm not sure if someone already pointed this out, but the reference at 29:40 is unnecessary. The reference would be needed if you were actually changing the pointer inside of the vector but the delete operator doesn't do that, it only changes the memory that's being pointed to by the pointer. Using: for (auto a : vSomeVector) delete a; would still work just fine, since it would create a copy of the pointer, and delete would still deallocate the memory location that's pointed to. You can double check that the pointer itself is unmodified by printing the value of each pointer in the vector before and after the delete. The address they hold should stay the same, even though the memory they point at becomes invalidated. Not really important, but figured I'd share anyway just in case someone was interested :) I love the video by the way.
Just finished pointing this out myself. Glad I'm not the only one who noticed. :) Was surprised to hear him make such a critical error in his explanation, but I guess it happens to the best.
Thank GOD for C#. Though your demonstration of polymorphism is somehow better than any other I've seen in higher level languages like C# which is a huge credit to your manner of explanation.
It is indeed a hugely important concept, and it also is important in other languages too, even though it may not be explicit. I think video is a good format for pointer understanding as it shows you things moving around in memory, something a book can only hint at.
@@rockapartie Given that pointers are essentially the same between the two (implicit void* casting aside) it sounds like that might be the go to for c++
12:40 in, things that will catch an unaware programmer... in my best 6th sense voice "I see dead references"... also memory leaks. Now that I've watched the video I'm really glad you hit on both of those points. In fairness, Pointers were the hardest part of C++ for me to get my head around. I've found that smart pointers simplify some processes when doing engine programming that relies on entangled subsystems (game engines are BAD about that) Weak and strong pointers become handy at that point. It does not make up got GOOD habits, but it IS useful.
I'm a C# developer and used C and C++ at the university. Modern C++ used with VS just fascinates me, please do more C++ videos and if you could do some compares with C# it would be very helpful. Thank you for the great video on pointers!
When you made that large section of memory in your picture for RAM I immediately thought you were going to say that it was fir chrome, and you did. Lol, thanks for that.
Absolute GEM! It is not only easy explanation to general pointers but also to virtual functions and memory allocations and smart pointers which are rarely touched by any topic named C++ pointers. Thumb Up-ed, subscribed and shared.
About to go back to college and I basically know nothing pertaining to C++ but watching this is getting me excited and wanting to understand more.. I'll be coming back to watch these in the future once I understand the language and can pick up on everything your teaching.. thank you, this is what I needed to remember if I still had the drive to learn like I did in my younger days.
Holy heck javid, i never fully understood pointers for the longest time doing c++, i now have a reference guide for pointers fundamentals...and actually understanding the darn things
I already know pointers but have to say I like your way of teaching, very polished, succinct and thorough. I like how you don't assume too much knowledge and quickly explain or elaborate things that some people might not know.
Hola Javid, thank you for all these great free lessons. Back here rewatching this because I ran into the smart pointers in the breakout PGE tutorial wiki and it threw me way way off then I remembered you had a pointer video. Thankfully! You’re incredible for making all these educational videos and making them free. I would be way behind where I am now in my programming journey if you never started this channel. I am incredibly thankful for all your work.. thank you, thank you, thank you.
Thanks for your kind words Lee, it's always pleasing to hear when someone has found the videos useful, and it keeps me motivated to keep going - which I will in the new year!
Even though I haven't progressed to using C or C++ yet, but learn some basics about programming using mainly Lua and Python, I found this video - and many others from you too - VERY useful. Your clear and organised style of explaining is a joy and it is very easy to follow you. Your dry sense of humor adds to the fun. Thanks for your efforts, javidx9
I love smart pointers. In a large application, I would rarely use a raw pointer. Should the object get deleted, all other raw pointer that reference are now dangling. No fun to debug if you dereference. A pointer used to reference a newly created object in the free store, in the presence of exceptions, you get memory leakage. I always use a unique_ptr when a object in the heap is initially created, in case of exception later in the code. Great vids, learned loads from you.
Undoubtly perfect "Englishman" made a C++ Pointer subject made easy and eloquently explained its inner working, briskly introducing smart pointer. Good (imaculate) work David.
This is about pointers in C, which are eventually included in C++ for backwards compatibility. Actual C++ pointers look like "std::unique_ptr" and are much "smarter".
I'm relatively new to C++ and I didn't have much troubles understanding what pointers are, though the syntax was a bit weird, but I really struggled with the question of "Why" would I even need them. Besides being completely obsessive about my memory management, I really struggled to come up with something that I couldn't do without pointers. Your example of polymorphism is absolutely brilliant, and you explained it as well as humanly possible. Thank you very much, I'll be sure to check out your other videos too!
Thanks! Simply, the primary use of pointers is to point at memory! Why move/copy whole objects when you can just use its pointer? It fits in a register!
Hi David, I've just started watching your videos these last days and they are just fantastic and so helpful and I really love the way how you explain things and teach them. As a beginner, I really want you to mak. A series of full courses about C++ to teach us the fundamentals and the basics and also the advanced stuffs about C++ that will really help us and motivate us to learn more and more and it will also help you too as this channel owner. So much respect to you sir, Thanks.
This is a perfect video about pointers. any other videos by somebody else are not necessary ...Just trying to write an original comment to point my point that I really enjoy watching Your videos to the point I even watched them when I have no clue about what they are and there is no point to watch them (a reference to the latest one, this is still black magic for me) ... Regards and Thank You
PHENOMENONAL VIDEO!! Very well thought out and presented. Excellent coding examples that reinforce understanding with illuminating graphics. Perfect amount of depth for a real fundamental base in a simple and easy-to-understand manner. A sign of a true expert with much experience who can also teach. Great job!!! Poignantly Pointing to the Point of Pointers without being Pointless. ;)
wow, thank you. All i gada say. I don't know why i decided to jump in and take on c/c++ as the first languages i learn, should have started with python. (I ended up learning python just as a result of getting frustrate with c++, started dipping into it and right away just seeing how simple it is in comparison and how the language it self clearly states the intent of the code, I ended up taking a break all together from c ++) Your videos though make it really easy for me to understand the things i was struggling with so I'm back on it now. Blows my mind how much information is out there and in so many formats. I can go through 10 videos some times and still not understand something and then finally find someone that just explains it in a way, in full detail very clearly so i can grasp it. What ever some of you guys are making in add revenue, isn't enough for the value in the content your putting out, that's for sure.
I might be learning on my own, but this is single handedly the best video on pointers! might be just the basics, but its an actual comprehensive explanation of those basics that make it understandable. Thank you so much for your help, LEGEND
Hilarious start around 01:15 .. :D and now i continue my journey towards the 2nd minute. Best wishes! (update, i finished watching this episode, ultra-invaluable, perfectly crafted and articulated knowledge. As usual. Although i'm nobody in C++ yet, but surely got hyped and inspired by watching the Right materials on the web.. ^^ God bless you : )
I just found your channel a couple of days ago and already subbed and bingewatched a good chunk of them. Very informative and I learned lots of things. Thank you for sharing your knowledge.
Amazing video. But for those trying today 16:20 : Char* cannot be cast into integer on 64bits system. So don't do: (int) pLocation0 but (void*) pLocation0.
Oh man, i've spent nearly 5 hours on a video, which is about 45 minutes long. From one video, i went on few other videos about pointers, even guys who were doing map and pictures from the pointers but still, this one was the best. Thanks man! And i have to go sleep cuz i need to wake up early..
I have had many interns who don’t understand the concept of pointers. And initially I didn’t understand because it so fundamental to CS. Then I found out that college students don’t get a semester of assembler programming anymore. And then it fell into place. So initially I took an hour to bring them up to scratch. And during those sessions I noticed that the * is very confusing to them in C (C++) as it basically means two different things. As an assignment and an operator for dereferencing aka getting the value from that address the pointer is pointing to. Then all of them understood. But I still am amazed how you can get through 4 years of college in Computer science and not fully understand the fundamentals of a computer.
Awesome channel! We were learning OOP this year at uni and the subject of pointers was confusing for most. It is a shame this video found me only now, but I will surely go back to it whenever I want to make sure that I am using pointers correctly and cleaning after myself. Pointers get confusing when I start using arrays of pointers and matrices of pointers which are required in the exercises we get. THANK YOU SO MUCH! Keep up the good work!
That's great to hear Adem, I tried with this video to show lots of other "interesting" things to put pointers in a broader perspective, so I'm pleased it helped.
I’m in a DS course right now and I’ve found the previous and current explanations for pointers inadequate, and most books haven’t explained it in a satisfactory manner. This video has been an immense help.
@@akashverma4280 Define 40%. Is it of 4, 8 or perhaps 16 GB? I have 16 GB and 2 screens of Chrome with about 10 tabs each and the total consumption is ~2 GB RAM according to Task Manager. That is too little imo. Certainly not enough to warrant this imfamous reputation I see everywhere. i.imgur.com/MPhDt4T.png
@@Leonhart_93 40% of my 4 Gig RAM on my potato pc. Sorry I'm broke. Multitasking becomes pain in ass. Although I've stopped Windows Update manually to allow some free RAM. I didn't mean to smear the reputation of Chrome. It's the best browser I've ever used.
I thank you so much for this javidx9. I don't know why something that's not really complicated for some reason is, or was for me. I'm learning to code "in reverse"; went from an interpreter language backwards and now learning C and lol, I hadn't even heard of "pointers" before this endeavor =)
It's a miraculix nobody thought of that before! :D A few funny names for special characters: # chainlink fence / tictactoe @ paperclip § fidget spinner ! baseball bat ~ wavelet ^ party hat ° halo
@@achtsekundenfurz7876 I just wish people would learn the proper names for (), [] and {} = parenthesis, brackets and braces, with the latter two having the optional modifiers of square and curly respectively, if 9ne must. There's only one set that should ever be referred to as brackets [] the other two are not brackets, ever. ;)
An interesting thing to note is that there's really no external "pointer" pointing to an array when you declare one. From the programmer's point of view, the declaration only allocates (sizeof(type) * number of elements) bytes, nothing more. The compiler/linker just makes array access/pointer arithmetic easier by "assigning" to an array A the address of the first element.
Pointers! The unique selling point of C and C++, and also the most abused (knowingly sometimes and sometimes not)! This is not my first taste of pointers, but like the intro, I have deviated from the 'formal' terminology ('reference' and 'dereference') and, in the context of pointers, rechristened (in my mind) the & operator as the 'address-of' operator and the * as the 'value-of' operator. N.B. Due to the lack of quality material on it, I would appreciate a 'Modern C++ gems' series someday :)
I clicked because I wondered how this concept could take a 42 minute video. It's always been a confusing thing to new people, but it's so simple. Im not being elitist, it's just there seems to mostly be an issue of when to use a pointer or a reference, and how other coders use language to relate. Sometimes you hear coders give examples where they say "you get a pointer to the object" when they mean a reference and vice versa. I was guilty of it myself, until I started to force it. I usually tell people that the difference between a pointer and a reference is like the difference of a .EXE versus a shortcut to that exe. A reference is the exe, a shortcut is the pointer. Its probably not the most informative analogy for it, but its all about knowing enough for now to get today's work done. Then relating it in future.
Just found your channel. Exceptional tutorials, thank you so much for this stuff. I learn some c/c++ years ago but just find these explaining these concepts. Cheers!
Circa 1985-ish, I started down the path to a CS degree. It was probably called something like IS or MIS at the time. The school I was at structured this so that first-year programming courses were taught in Pascal. Second-year was in C. Of course, we didn't call it "K&R C" at the time, because the ANSI standard wasn't complete yet. I noticed during the C part of the program that in every class, there would inevitably be someone sitting in the front row who, sometime well past the first week or two of class, would suddenly ask "Wait. What's a pointer again?" Pascal had pointers -- oversimplified and of limited utility, but clearly pointy pointers used to point at things. How do you make it as far as an upper-division class in a discipline that critically requires a good understanding of pointiness and then ask "wait, what's a pointer?" This would bring the entire class to a screeching halt for a week while the Prof set about clearing up the confusion of a student who would inevitably take a W anyway. This happened in at least three different courses, and with a different person each time. And THAT, my friends, is why I bailed on software as a career and became a Certified Netware Administrator and embarked on a career in Ops, where our job is to make the product look like it works properly.
I don't know if it's gonna be of use to anyone, but I personally prefer to think of declaration like T *t_ptr; as of an equation. It means if you dereference t_ptr, you'll get something of type T, and therefore t_ptr itself must be of type pointer to T. It facilitates understanding more complex cases like function pointers or arrays of pointers easier. Just remember that function call () and indexing [] operators have higher priority, and thus are executed first, unless you change the order with parentheses. For example, you can read the declaration T *f(); as follows: if you call f and dereference the result, you'll get T, therefore f is a function that returns a pointer to T. On the other hand, the declaration T (*f)(); means if you dereference f and call it, you'll get T, therefore f is a pointer to a function that takes nothing and returns T.
The problem I have with pointers is that as a beginner, you don't know when or why you would use them. I was fine with the concept of storing an address, but at beginner level you aren't writing very complex code and you cant see why you would want to store an address. It seemed like it was just a way to break encapsulation to access some variable. Not to mention the fact that there are references as well which are similar enough to cause more confusion.
Pointers are really fundamental, and I would hope that students learn them early. They should be taught as a way to refer to a very large piece of data. For instance, if you wanted to load an entire image from the hard drive, there is no way you could just fit that in a normal variable; the stack is just too small. So, you ask the operating system for a big chunk of memory, and it gives you a pointer to that memory. Obviously, there are other uses as well, but this is the most direct and understandable, IMO.
I musst admit, seeing this video from someone who actually knows what he talks about is a releaf. It helped me allot more than "Look and than we can do this and it makes this" without the "when we do this it does this and makes this"
This was so ENLIGHTENING ! , Really I was confused just because of what you pointed out, Using * to declare and to to get value of.. Thank you so much.🙏🙏
I think a lot of people have trouble with pointers because of the way it is declared. In other words, these two forms are considered approved: a) int* ptrExample = & someVariable; b) int *ptrExample = & someVariable; In form a), you can visually understand that the pointer variable is only ptrExample, because "nothing touches it", it's a variable like others. However, in form b) visually, the programmer can understand that the pointer variable created is *ptrExample, including the asterisk. [1] I think that is why confusion occurs when dereferencing the pointer and getting the value it's pointing to. Because you must apply the dereference operator (*), when you initially thought that your variable already contained it. [1] I think this is one of the reasons, maybe the main one, obviously not the only one.
"basic use of pointers"
David, you should have "in depth c++" series created. Keeping such precious knowledge to yourself is a crime :D
Hi Aleksei, I may do a C++ series next year, it depends, there are already a lot of resources available, but I have been considering doing a short run of "Back To Basics" videos
@@javidx9 hey dude, really appreciate you sharing the delicate yet easy to understand explanation on such a crucial topic. please make the "back to basics" video :)
@@javidx9 it's been a year! i would love a series like this
@@javidx9 please consider it or Can you share resources ?
javidx9 please do it, I will be starting a course in it but your UA-cam videos will be a life saver I’m sure
This guy is a genius, he is gentle, and wants everyone to learn at their own pace and on their own terms. He explains things like a gentleman and holds no judgement or arrogance towards others. He is in fact a PhD holder in Computer Science, as well as an experienced professional in the real world. It does not get any higher for anyone. He is undoubtable worth his weight in gold. Creative minds like this belong on the edge of technology and business
Well said
Grrrr!
12:00-12:10 "The pointers work in a space defined by the type of object they are pointing to" - This was extremely helpful and concise
I've seen 4+ c++ pointer tutorials, and this one is the best one. You managed to explain the basics really well. I hope you will find time to make more videos covering the basics of c++
Thanks Kamil! I'm thinking about doing some sort of "C++ Basics" series, but there are a lot of resources already out there. I'll keep thinking about it though for the new year.
I was understanding everything (kinda) until 21:15, after that I lost track of what you were doing, I need to rewatch this many times but this is pure gold, I would like to express my deepest thanks to you for taking almost an hour of your life to share this super useful knowledge.
Same here. Exact same point in the video I got lost.
Same 😂
Same here. You commented/watched this video 2 years ago. How is your programming skill in C++ now? Are you able to understand beyond 21:15?
@@MikeMcRoberts Same here. How is your programming skill in C++ now after a year ago of watching the video? Are you able to understand beyond 21:15?
@@MikeMcRoberts R u Zoro?
This channel is such a gem, thank you Javidx9.
Hey no problem Rory, thanks!
"I think I have covered all of the most basic uses of pointers in C ++" 41:28
I can not even imagine the advanced.
rofl tru dat
21 hours later, 13 skull fractures form banging your head in your desk and wall, mid level brain damage from drinking 92 redbulls, damaged vocal cords from screaming at your screen and your eyes in a constant clash between dryness from looking at a screen for so long and wetness from the pool of tears your formed before your tear ducts where completely empty, you understand the advanced parts if pointers.
int *(*f(void (*)(void *))(void *);
@@Mateus.007
This is bad and hard to read i hope no one use it.
@@xrafter In the C standart library there's a function like this:
void (*signal(int, void (*)(int)))(int);
Awesome video. Usually an explanation of pointers is just the first minute of this, and an assertion that they're really straightforward. Never usually go further and actually deal with how they can be confusing. Thank you!
I watched this once, and I'll watch this even twice or thrice or whatever it takes to thoroughly understand what's going on here. This is one of the best educative videos I've ever seen. I think it'll take me weeks of playing and experimenting with code to figure out the complexity of this stuff. Thank you very much!
This is one of the absolute best videos on the internet regarding pointer fundamentals. I recommend this to people who are new to the language any time I see them struggling to really grasp what pointers are and how they work.
One thing I do wish you had gone over in this video (and would perhaps be a good topic for a supplementary video) is the differences between taking parameters by value, by reference, by pointer, by pointer to pointer, and by reference to pointer which I find to be the most common 4 ways to pass values into functions.
For instance, when you start needing to develop application layers that are doing low level operations (like pointer arithmetic on a byte buffer), it can be very easy to make mistakes like not realizing that you need to either return a modified pointer from the function so that you can use the updated memory address externally or take a reference or pointer to a pointer as the parameter type.
Also, I like your bit about smart pointers at the end, however, I think a good rule of thumb is that smart pointers are useful when they are being used how they were intended to be used, which is to denote ownership and not just "because it's modern".
In otherwords if this is a low level piece of code that needs to be closely managed and optimized, like designing a custom data structure like an Octree implementation, then it is not a good idea to use smart pointers. If however, you are working on systems within an API where you need to denote "has-a" relationship component ownership of difference objects, then having unique and shared pointers can be useful and appropriate there.
Instantly liked after the definition of a pointer without a prompt.
Also, I've been inexplicably drawn to C++ since I was a teenager, but couldn't quite start learning it, but now there's a huge UA-cam library, so what better time to start learning.
I just started c++ and without having seen the entire video, I already know this will be gold
31:25 mindblowing part. In my university, professor gave us a programming exam that used pointers to vector cells. You're so clever.
I have not done C/C++ in 20 years. I miss it. Thanks fir the stroll down memory lane.
Well you'll still miss your C/C++ memories from 20 years ago when you start reading about C++11 and discover "smart" pointers.
Excellent! This is as calming as watching a documentary about lions on the savanna!
I managed to complete a programming test for a post-grad job with this refresher on ptrs! thank you
Note to myself: What I’ve learned from this video. Pointers are variables that hold memory addresses. You need to specify what datatype the pointer points to. A pointer of int can’t point to a double. A pointer of int can point to a memory address that stores an int value. Pointers are used in polymorphism to point from a base class to a derived class and have different types of objects (which all have one thing in common, they’re derived from the base class) this means it’s valid for an array or a vector to store both the base class object and derived class object in the same container and treats them as all the same. Thanks so much!
So I learned c++ in school and college and didn't know what & and * was all about, thanks for the in-depth explanation. Thank you so much.
Nicely explained! Definitely one of the best programming channels on UA-cam that actually explains things in-depth.
Vector memory allocation was amazing, makes so much sense! Thanks for taking your time to explain it in such depth!
"The name of the array is a pointer" which I remember from other lessons.
When the "*" is used to request the value of some pointer variable is called "dereference" as far as I understood it.
int a = 5;
int* b = &a;
cout
the word dereference isn't intuitive. "value of operator" makes far more sense
UA-cam was on Auto Play mode and suddenly this video came up. I'm so happy that I didn't skip.
This is by far the best introduction I've ever got into pointers.
So far, no book was able to teach me what you did in a couple of minutes.
And +1 for the Chrome joke :D
Edit: I forgot to say thank you. So: Thank you!
lol, cheers Devran! :D
in 40 minutes you cleared up what my professor couldn't explain in 3 hours, thank you
You're teaching this for free when I pay thousands for a shitty explanation in school.
God bless.
Oof this one hit hard today
I'm not sure if someone already pointed this out, but the reference at 29:40 is unnecessary. The reference would be needed if you were actually changing the pointer inside of the vector but the delete operator doesn't do that, it only changes the memory that's being pointed to by the pointer. Using:
for (auto a : vSomeVector)
delete a;
would still work just fine, since it would create a copy of the pointer, and delete would still deallocate the memory location that's pointed to.
You can double check that the pointer itself is unmodified by printing the value of each pointer in the vector before and after the delete. The address they hold should stay the same, even though the memory they point at becomes invalidated.
Not really important, but figured I'd share anyway just in case someone was interested :) I love the video by the way.
Just finished pointing this out myself. Glad I'm not the only one who noticed. :)
Was surprised to hear him make such a critical error in his explanation, but I guess it happens to the best.
Thank GOD for C#. Though your demonstration of polymorphism is somehow better than any other I've seen in higher level languages like C# which is a huge credit to your manner of explanation.
C# is such a lazy language
@@SCARRIOR What you call lazy, I call Abstraction 😋
Probably the single most import concept in C++ to grasp, and even more so, the most butchered topic you'll ever find in books.
It is indeed a hugely important concept, and it also is important in other languages too, even though it may not be explicit. I think video is a good format for pointer understanding as it shows you things moving around in memory, something a book can only hint at.
Agreed, pointers are seen as this powerful tool that nobody really understands. It is really powerful indeed, but they aren't complex or anything.
@@rockapartie looks like a book i'll find useful - thanks for mentioning it
@@rockapartie Given that pointers are essentially the same between the two (implicit void* casting aside) it sounds like that might be the go to for c++
@@joestevenson5568 C also does not have passing by reference.
12:40 in, things that will catch an unaware programmer... in my best 6th sense voice "I see dead references"... also memory leaks.
Now that I've watched the video I'm really glad you hit on both of those points. In fairness, Pointers were the hardest part of C++ for me to get my head around.
I've found that smart pointers simplify some processes when doing engine programming that relies on entangled subsystems (game engines are BAD about that) Weak and strong pointers become handy at that point. It does not make up got GOOD habits, but it IS useful.
I'm a C# developer and used C and C++ at the university. Modern C++ used with VS just fascinates me, please do more C++ videos and if you could do some compares with C# it would be very helpful.
Thank you for the great video on pointers!
I've always considered C# to be Borland's Delphi with a C syntax.
When you made that large section of memory in your picture for RAM I immediately thought you were going to say that it was fir chrome, and you did. Lol, thanks for that.
Absolute GEM! It is not only easy explanation to general pointers but also to virtual functions and memory allocations and smart pointers which are rarely touched by any topic named C++ pointers. Thumb Up-ed, subscribed and shared.
Hi Artur, I really appreciate that, thanks a lot!
Lol I love the “what are pointers” Art!
About to go back to college and I basically know nothing pertaining to C++ but watching this is getting me excited and wanting to understand more.. I'll be coming back to watch these in the future once I understand the language and can pick up on everything your teaching.. thank you, this is what I needed to remember if I still had the drive to learn like I did in my younger days.
Holy heck javid, i never fully understood pointers for the longest time doing c++, i now have a reference guide for pointers fundamentals...and actually understanding the darn things
That's great to hear Eternia, thanks!
I will replay this video as many times as it takes for me to grasp the idea of pointers.
i'm not kidding.
I already know pointers but have to say I like your way of teaching, very polished, succinct and thorough. I like how you don't assume too much knowledge and quickly explain or elaborate things that some people might not know.
Hola Javid, thank you for all these great free lessons. Back here rewatching this because I ran into the smart pointers in the breakout PGE tutorial wiki and it threw me way way off then I remembered you had a pointer video. Thankfully! You’re incredible for making all these educational videos and making them free. I would be way behind where I am now in my programming journey if you never started this channel. I am incredibly thankful for all your work..
thank you, thank you, thank you.
Thanks for your kind words Lee, it's always pleasing to hear when someone has found the videos useful, and it keeps me motivated to keep going - which I will in the new year!
Even though I haven't progressed to using C or C++ yet, but learn some basics about programming using mainly Lua and Python, I found this video - and many others from you too - VERY useful. Your clear and organised style of explaining is a joy and it is very easy to follow you. Your dry sense of humor adds to the fun. Thanks for your efforts, javidx9
Hey no problem and thanks Rozzman!
I love smart pointers. In a large application, I would rarely use a raw pointer. Should the object get deleted, all other raw pointer that reference are now dangling. No fun to debug if you dereference.
A pointer used to reference a newly created object in the free store, in the presence of exceptions, you get memory leakage.
I always use a unique_ptr when a object in the heap is initially created, in case of exception later in the code.
Great vids, learned loads from you.
Undoubtly perfect "Englishman" made a C++ Pointer subject made easy and eloquently explained its inner working, briskly introducing smart pointer. Good (imaculate) work David.
Great video! I’ve almost no programming exp and I could still mostly follow this. The sketches were a critical part of making this work. Well done!
This is about pointers in C, which are eventually included in C++ for backwards compatibility. Actual C++ pointers look like "std::unique_ptr" and are much "smarter".
I'm relatively new to C++ and I didn't have much troubles understanding what pointers are, though the syntax was a bit weird, but I really struggled with the question of "Why" would I even need them. Besides being completely obsessive about my memory management, I really struggled to come up with something that I couldn't do without pointers. Your example of polymorphism is absolutely brilliant, and you explained it as well as humanly possible. Thank you very much, I'll be sure to check out your other videos too!
Thanks! Simply, the primary use of pointers is to point at memory! Why move/copy whole objects when you can just use its pointer? It fits in a register!
Hi David, I've just started watching your videos these last days and they are just fantastic and so helpful and I really love the way how you explain things and teach them. As a beginner, I really want you to mak. A series of full courses about C++ to teach us the fundamentals and the basics and also the advanced stuffs about C++ that will really help us and motivate us to learn more and more and it will also help you too as this channel owner.
So much respect to you sir, Thanks.
still trying to wrap my head around pointers. This video helped so much! I need to practice because that's how I learn best.
Its all about the practice, videos, guides and tutorials will only get you so far, at some point YOU need to write the code.
I've seen a lot of material trying to introduce pointers and I have to say I think yours is the best and most intuitive of them all, and it's free!
This is a perfect video about pointers. any other videos by somebody else are not necessary ...Just trying to write an original comment to point my point that I really enjoy watching Your videos to the point I even watched them when I have no clue about what they are and there is no point to watch them (a reference to the latest one, this is still black magic for me) ... Regards and Thank You
Haven't programmed in C/C++ in a while. This brings the joy back
PHENOMENONAL VIDEO!! Very well thought out and presented. Excellent coding examples that reinforce understanding with illuminating graphics. Perfect amount of depth for a real fundamental base in a simple and easy-to-understand manner. A sign of a true expert with much experience who can also teach. Great job!!!
Poignantly Pointing to the Point of Pointers without being Pointless. ;)
wow, thank you. All i gada say. I don't know why i decided to jump in and take on c/c++ as the first languages i learn, should have started with python. (I ended up learning python just as a result of getting frustrate with c++, started dipping into it and right away just seeing how simple it is in comparison and how the language it self clearly states the intent of the code, I ended up taking a break all together from c ++) Your videos though make it really easy for me to understand the things i was struggling with so I'm back on it now. Blows my mind how much information is out there and in so many formats. I can go through 10 videos some times and still not understand something and then finally find someone that just explains it in a way, in full detail very clearly so i can grasp it. What ever some of you guys are making in add revenue, isn't enough for the value in the content your putting out, that's for sure.
I might be learning on my own, but this is single handedly the best video on pointers! might be just the basics, but its an actual comprehensive explanation of those basics that make it understandable. Thank you so much for your help, LEGEND
Hilarious start around 01:15 .. :D and now i continue my journey towards the 2nd minute. Best wishes! (update, i finished watching this episode, ultra-invaluable, perfectly crafted and articulated knowledge. As usual. Although i'm nobody in C++ yet, but surely got hyped and inspired by watching the Right materials on the web.. ^^ God bless you : )
I just found your channel a couple of days ago and already subbed and bingewatched a good chunk of them. Very informative and I learned lots of things. Thank you for sharing your knowledge.
Didn't think i'd learn new things about pointers after programming in C for 8 years. color me surprised!
note, when casting to int the address of pointers to char (about 17:20 ) , compile will fail unless the flag -fpermissive is enabled.
That's true, I had the same problem. An alternative is to use `intptr_t` as cast.
Amazing video.
But for those trying today 16:20 : Char* cannot be cast into integer on 64bits system.
So don't do: (int) pLocation0 but (void*) pLocation0.
Oh man, i've spent nearly 5 hours on a video, which is about 45 minutes long. From one video, i went on few other videos about pointers, even guys who were doing map and pictures from the pointers but still, this one was the best. Thanks man! And i have to go sleep cuz i need to wake up early..
One of the best videos! A Pointer is just a variable that holds a memory address.!!
I have had many interns who don’t understand the concept of pointers. And initially I didn’t understand because it so fundamental to CS. Then I found out that college students don’t get a semester of assembler programming anymore. And then it fell into place. So initially I took an hour to bring them up to scratch. And during those sessions I noticed that the * is very confusing to them in C (C++) as it basically means two different things. As an assignment and an operator for dereferencing aka getting the value from that address the pointer is pointing to. Then all of them understood.
But I still am amazed how you can get through 4 years of college in Computer science and not fully understand the fundamentals of a computer.
thank you very much for this kind of detailed video, was super helpful and easy to follow. I'm new in C++ and it helped me a lot
Awesome channel! We were learning OOP this year at uni and the subject of pointers was confusing for most. It is a shame this video found me only now, but I will surely go back to it whenever I want to make sure that I am using pointers correctly and cleaning after myself. Pointers get confusing when I start using arrays of pointers and matrices of pointers which are required in the exercises we get. THANK YOU SO MUCH! Keep up the good work!
excellent explanation, definitely cleared up a couple of things I misunderstood about the language.
That's great to hear Adem, I tried with this video to show lots of other "interesting" things to put pointers in a broader perspective, so I'm pleased it helped.
This video is awesome 👌
I've been struggling with pointers for awhile and you explain the concepts clearly and throughly
very informative, and helped me greatly to understand and more importantly less fearful of use of pointers
I really appreciate your delivery and concise examples and descriptions. Keep it up! :D
6 minutes in and I feel like a professional already!
Hi Marmori, Don't rush these things :D
Okay saw the console game engine, and the pixel engine, and now this. I hit subscribe, and I am not disappointed at all. Keep up the great work!
This was the first thing we learned in my data structures class. Thanks for the video! Enjoying it.
Hi LaJola, yeah effective data structure management would be impossible without pointers
I’m in a DS course right now and I’ve found the previous and current explanations for pointers inadequate, and most books haven’t explained it in a satisfactory manner. This video has been an immense help.
32:05
Chrome: Got some RAM?
OS : Actually ther...
Chrome : Thanks!
It can have all of the memory of my PC, if that's what it takes to run at max speed. The OS will afterwards balance it as needed by other programs.
@@Leonhart_93 Chrome takes advantage of OS generosity, lol. What does it need 40% RAM for when only 1 tab is open smh.
@@akashverma4280 Define 40%. Is it of 4, 8 or perhaps 16 GB? I have 16 GB and 2 screens of Chrome with about 10 tabs each and the total consumption is ~2 GB RAM according to Task Manager.
That is too little imo. Certainly not enough to warrant this imfamous reputation I see everywhere.
i.imgur.com/MPhDt4T.png
@@Leonhart_93 40% of my 4 Gig RAM on my potato pc. Sorry I'm broke. Multitasking becomes pain in ass. Although I've stopped Windows Update manually to allow some free RAM.
I didn't mean to smear the reputation of Chrome. It's the best browser I've ever used.
@@Leonhart_93 "That is too little imo. "
Too little? What do you mean?
Thanks. This is the best pointer tutorial I have ever seen. You made pointers understandable.
How did the UA-cam algorithm know that i needed to know this? I was about to look it up and it showed in the recommended section lol
I thank you so much for this javidx9. I don't know why something that's not really complicated for some reason is, or was for me. I'm learning to code "in reverse"; went from an interpreter language backwards and now learning C and lol, I hadn't even heard of "pointers" before this endeavor =)
Man. In just one night of watching your videos, so many of my questions have been answered.
Well i am pleased you are finding them useful Chris, and the feedback is much appreciated!
Really clear and understandable, David.
Nice video as always.
Merry Christmas.
Merry Christmas Daniel!
Every time you say "Asterix" for asterisk, I cannot stop myself thinking: Why don't we call "&" the Obelix operator?
One is rather small, the other one is round and large. Seems very fitting.
That is genius. People should adopt this. Its very easy to remember and it makes sens
It's a miraculix nobody thought of that before! :D
A few funny names for special characters:
# chainlink fence / tictactoe
@ paperclip
§ fidget spinner
! baseball bat
~ wavelet
^ party hat
° halo
@@achtsekundenfurz7876 I just wish people would learn the proper names for (), [] and {} = parenthesis, brackets and braces, with the latter two having the optional modifiers of square and curly respectively, if 9ne must. There's only one set that should ever be referred to as brackets [] the other two are not brackets, ever. ;)
@@tonyfremont Tbf, "parenthesis" sounds like an ugly medical condition, so I can understand why few people use that word...
Great video. Thanks for the vector drawings in RAM! very clearly
An interesting thing to note is that there's really no external "pointer" pointing to an array when you declare one. From the programmer's point of view, the declaration only allocates (sizeof(type) * number of elements) bytes, nothing more. The compiler/linker just makes array access/pointer arithmetic easier by "assigning" to an array A the address of the first element.
A great point John
@@javidx9 Haha, no pun intended! :)
Pointers! The unique selling point of C and C++, and also the most abused (knowingly sometimes and sometimes not)!
This is not my first taste of pointers, but like the intro, I have deviated from the 'formal' terminology ('reference' and 'dereference') and, in the context of pointers, rechristened (in my mind) the & operator as the 'address-of' operator and the * as the 'value-of' operator.
N.B. Due to the lack of quality material on it, I would appreciate a 'Modern C++ gems' series someday :)
I can answer it better than you in 3 words:
They are a tresure.
These cute little things saved me a lot in the past
Hey Dirty, Pointers are indeed tiny powerful programming weapons :D
I prayed for an in depth video on pointers in C++.
I clicked because I wondered how this concept could take a 42 minute video. It's always been a confusing thing to new people, but it's so simple. Im not being elitist, it's just there seems to mostly be an issue of when to use a pointer or a reference, and how other coders use language to relate. Sometimes you hear coders give examples where they say "you get a pointer to the object" when they mean a reference and vice versa. I was guilty of it myself, until I started to force it. I usually tell people that the difference between a pointer and a reference is like the difference of a .EXE versus a shortcut to that exe. A reference is the exe, a shortcut is the pointer. Its probably not the most informative analogy for it, but its all about knowing enough for now to get today's work done. Then relating it in future.
Just found your channel. Exceptional tutorials, thank you so much for this stuff. I learn some c/c++ years ago but just find these explaining these concepts. Cheers!
Circa 1985-ish, I started down the path to a CS degree. It was probably called something like IS or MIS at the time. The school I was at structured this so that first-year programming courses were taught in Pascal. Second-year was in C. Of course, we didn't call it "K&R C" at the time, because the ANSI standard wasn't complete yet.
I noticed during the C part of the program that in every class, there would inevitably be someone sitting in the front row who, sometime well past the first week or two of class, would suddenly ask "Wait. What's a pointer again?"
Pascal had pointers -- oversimplified and of limited utility, but clearly pointy pointers used to point at things. How do you make it as far as an upper-division class in a discipline that critically requires a good understanding of pointiness and then ask "wait, what's a pointer?" This would bring the entire class to a screeching halt for a week while the Prof set about clearing up the confusion of a student who would inevitably take a W anyway. This happened in at least three different courses, and with a different person each time.
And THAT, my friends, is why I bailed on software as a career and became a Certified Netware Administrator and embarked on a career in Ops, where our job is to make the product look like it works properly.
Again. Thank you!!! I will now feel comfortable taking this class.
I don't know if it's gonna be of use to anyone, but I personally prefer to think of declaration like
T *t_ptr;
as of an equation. It means if you dereference t_ptr, you'll get something of type T, and therefore t_ptr itself must be of type pointer to T. It facilitates understanding more complex cases like function pointers or arrays of pointers easier. Just remember that function call () and indexing [] operators have higher priority, and thus are executed first, unless you change the order with parentheses. For example, you can read the declaration
T *f();
as follows: if you call f and dereference the result, you'll get T, therefore f is a function that returns a pointer to T. On the other hand, the declaration
T (*f)();
means if you dereference f and call it, you'll get T, therefore f is a pointer to a function that takes nothing and returns T.
Fantastic approach to presenting complicated information. Great video
mate, i cant tell you how many times your videos have helped me out. thanks!
Hey no problem buddy, good to hear.
Super helpful video, all the concepts are very thoroughly explained, really appreciate uploading of these videos.
Hi Idaisa, cheers!
Wow this video is freaking awesome, this man was born to teach. Subscribed
The problem I have with pointers is that as a beginner, you don't know when or why you would use them. I was fine with the concept of storing an address, but at beginner level you aren't writing very complex code and you cant see why you would want to store an address. It seemed like it was just a way to break encapsulation to access some variable. Not to mention the fact that there are references as well which are similar enough to cause more confusion.
Pointers are really fundamental, and I would hope that students learn them early. They should be taught as a way to refer to a very large piece of data. For instance, if you wanted to load an entire image from the hard drive, there is no way you could just fit that in a normal variable; the stack is just too small. So, you ask the operating system for a big chunk of memory, and it gives you a pointer to that memory.
Obviously, there are other uses as well, but this is the most direct and understandable, IMO.
i'm feel proud of easily understand this video after a year of learn cpp by myself
Man, I wish I had this video when I was taking Computer Architecture and Systems Programming in college.
The best explanation on pointers ever! I really hope you would create more c++ videos🤘
I musst admit, seeing this video from someone who actually knows what he talks about is a releaf. It helped me allot more than "Look and than we can do this and it makes this" without the "when we do this it does this and makes this"
This was so ENLIGHTENING ! , Really I was confused just because of what you pointed out, Using * to declare and to to get value of.. Thank you so much.🙏🙏
ur a legend man, best C++ channel on youtube
I think a lot of people have trouble with pointers because of the way it is declared.
In other words, these two forms are considered approved:
a) int* ptrExample = & someVariable;
b) int *ptrExample = & someVariable;
In form a), you can visually understand that the pointer variable is only ptrExample, because "nothing touches it", it's a variable like others. However, in form b) visually, the programmer can understand that the pointer variable created is *ptrExample, including the asterisk.
[1] I think that is why confusion occurs when dereferencing the pointer and getting the value it's pointing to. Because you must apply the dereference operator (*), when you initially thought that your variable already contained it.
[1] I think this is one of the reasons, maybe the main one, obviously not the only one.
you have a clear talent for teaching, thanks so much for this
The