Dynamic Memory Allocation -- C++ Pointers Tutorial [8]

  Рет қаралды 20,759

Professor Hank Stalica

Professor Hank Stalica

Жыл бұрын

Let's learn about dynamic memory allocation, what it is, how to use it and when to use it. We'll cover the new and delete operators and talk about memory leaks and how to avoid them. In this C++ programming tutorial for beginners, you'll learn through coding examples done using Visual Studio 2022 C++ Community.
In addition, you'll see how to create a new array and a new int using the new operator and how to free the memory by using the delete operator.
// Learn More
Pointers Playlist ⇒ • Playlist
• Playlist
C++ Programming for Everyone ⇒ • Playlist
// Consider supporting this channel in multiple ways
ko-fi.com/professorhank
paypal.me/hankstalica1
Bitcoin: 177wfkQwzXiC8o2whQMVpSyuWUs95krKYB
Dogecoin: DRK2HDp3ZkkbFpvGZnVgMVosnBhPv8r3uP

Пікірлер: 43
@broozkej8518
@broozkej8518 Жыл бұрын
I’m a second semester cpp student and you literally cleared up so much information compared to my hours of reviewing and reading online. Thanks bro
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
You're so welcome!
@rizzmaster5000
@rizzmaster5000 Ай бұрын
Excellent explanation, I love how meticulous you were when describing all the ins and outs. Great video!
@ProfessorHankStalica
@ProfessorHankStalica Ай бұрын
Thanks so much!
@treyandrews201
@treyandrews201 Жыл бұрын
I'm not a student of yours but I am a cs student. Thank you for the video. Your way of explaining it is very easy to understand. I see you have a whole catalog of videos so I'm definitely going to be relying on you to help understand the more difficult concepts
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Thanks and welcome
@linkofcrafting8929
@linkofcrafting8929 Жыл бұрын
This is helping me in my second college c++ class!
@BigCatSoftware
@BigCatSoftware 6 ай бұрын
This was so easy to understand. Thank you! Best memory allocation video on KZfaq!
@ProfessorHankStalica
@ProfessorHankStalica 6 ай бұрын
You're very welcome!
@lorddoinkus6349
@lorddoinkus6349 Жыл бұрын
One of the topics I've had the most trouble with and this explained what a full semester couldn't!
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Glad you found it useful. Best of luck to you in the future!
@Ur_LittleLolipop
@Ur_LittleLolipop Жыл бұрын
Thank you for making this available! I can't wait for the next lecture.
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
You are welcome. I have one more video planned for this series. I'm hoping to have it ready by Friday.
@matthewhrndz
@matthewhrndz Жыл бұрын
By far the best resource for learning about dynamic memory allocation! Using this video to study for my final next week :)
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Hi, Matthew. Thanks tons for the kind words and glad you find it helpful!
@ARSIL_AFRIDI
@ARSIL_AFRIDI Жыл бұрын
Great sir
@mohamedboubakeur4554
@mohamedboubakeur4554 Ай бұрын
Thanks for teaching , sir 😊
@mohamednusair2722
@mohamednusair2722 3 ай бұрын
i understand clearly. 😍
@GEAG08
@GEAG08 Жыл бұрын
Best explanation ever, would have loved to listen what you said before doing the outro haha, but anyway, thanks for these videos!
@Truth_Seeker1202
@Truth_Seeker1202 Жыл бұрын
Best video on dynamic memory allocation
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Glad you found it useful and thanks for the comment!
@dunyagg00
@dunyagg00 10 ай бұрын
Thank you sir !
@ProfessorHankStalica
@ProfessorHankStalica 10 ай бұрын
Most welcome!
@joey6047
@joey6047 Жыл бұрын
Thank u Hank :)
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Hi, Joey. I'm really happy you found the video useful. And thanks for the PayPal contribution. I really appreciate it!
@sameaspastmueed
@sameaspastmueed Жыл бұрын
Hey, hank, I really appreciate you for making this available to everyone l. Was this the last lecture on pointers for now?
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Thanks for the kind words! I think I have one more to do in this series for now, and that will cover returning pointers from functions.
@liboyan7010
@liboyan7010 Жыл бұрын
@@ProfessorHankStalica Pointer to C++ Classes??
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Just like any other type of variable. Assume a class definition named Foo. Then, Foo* f = new Foo;
@syedimadhaqqi4340
@syedimadhaqqi4340 7 ай бұрын
Dear Professor, This is the best video on this topic I have come across. I want to know how can I get the "heap" memory address of the "new int" stored in int *n or int* o. Dereferencing n and o gives garbage output.
@ProfessorHankStalica
@ProfessorHankStalica 6 ай бұрын
Not sure I understand the question. You can share a snippet of code of what you are trying to do?
@stevenrashid5810
@stevenrashid5810 Ай бұрын
First of all great, amazing video but arent we supposed to reassign the pointer to nullptr...after deleting the memory?
@ProfessorHankStalica
@ProfessorHankStalica Ай бұрын
That's best practice, definitely. There's no syntactical requirement to do so though.
@stevenrashid5810
@stevenrashid5810 Ай бұрын
@@ProfessorHankStalica Thank you for the explanation
@qqqqssss510
@qqqqssss510 Ай бұрын
i think there is a mistake in the video. The memory for n (the pointer itself) is allocated on the stack when the main function is called. This allocation happens at runtime, not at compile time.. during compile time actual physical memory is not allocated to the variables because main is called like a normal function. n is allocated at run time not compile time . same with all other vars in the video.
@ProfessorHankStalica
@ProfessorHankStalica 29 күн бұрын
Of course you are correct. Our text only talks about compile time vs run time at this level so I stuck with that to make it less confusing for our students by staying consistent with the text. A proper assembly programming course will spell it out in detail, which is beyond the scope of this course and video.
@user-no9xf5ng4v
@user-no9xf5ng4v 2 күн бұрын
Why bald guy is always so fantastic af
@ProfessorHankStalica
@ProfessorHankStalica Күн бұрын
It's the sexual solar panels. 🤔
@mitchoulina4324
@mitchoulina4324 4 ай бұрын
dynamic hair allocation failed 💀 (jk awesome video) u are awesome
@ProfessorHankStalica
@ProfessorHankStalica 4 ай бұрын
Big time, but think of all the money I saved on dating. 🤣🤪😆
@mitchoulina4324
@mitchoulina4324 4 ай бұрын
@@ProfessorHankStalica 😂 respect.
@azizbeksavkimov7279
@azizbeksavkimov7279 Жыл бұрын
Trypophobia (((
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
I know, I'm sorry. I've switched backgrounds in my recent videos.
Returning Pointers from Functions -- C++ Pointers Tutorial [9]
11:52
Professor Hank Stalica
Рет қаралды 3,6 М.
OMG😳 #tiktok #shorts #potapova_blog
00:58
Potapova_blog
Рет қаралды 4,2 МЛН
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 25 МЛН
JSON Parser 100% From Scratch in Haskell (only 111 lines)
1:50:07
new & delete Operators For Dynamic Memory Allocation | C++ Tutorial
15:52
Portfolio Courses
Рет қаралды 26 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,1 МЛН
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,4 МЛН
Finally Fix Your Issues With JS/React Memory Management 😤
20:13
Jack Herrington
Рет қаралды 81 М.
Dynamic Memory Allocation | C Programming Tutorial
31:51
Portfolio Courses
Рет қаралды 77 М.
Garbage Collection (Mark & Sweep) - Computerphile
16:22
Computerphile
Рет қаралды 236 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 285 М.
OMG😳 #tiktok #shorts #potapova_blog
00:58
Potapova_blog
Рет қаралды 4,2 МЛН