Dynamically Allocate An Array Of Structs | C Programming Tutorial

  Рет қаралды 33,929

Portfolio Courses

Portfolio Courses

Жыл бұрын

How to dynamically allocate an array of structs in C, including how to use realloc() to re-allocate and increase the size of the array, and a warning about potential memory leaks that can occur if we forget to free dynamically allocated memory that the array struct members themselves point to (including how to prevent the memory leak). Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Пікірлер: 46
@r0drigo360
@r0drigo360 Жыл бұрын
I was trying to fix a bug for the last 3 hours. I tried StackOverflow and all kinds of forums and couldn't find an answer until I watched your video🙌 Thanks a lot !!!!!!!!!!!
@MrSnitsarenko
@MrSnitsarenko
Amazing explanation! I have spent literally a week debugging a code, with googling and many articles StackOverflow etc. Usually big vague paragraphs, and no answer at the end! and here, the author right away clearly points out that you have to allocate memory for struct members as well and use strcpy. Thank you!
@DataToTheZero
@DataToTheZero
Outstanding presentation as always! I'd like to suggest an enhancement to further streamline the management of dynamic memory, especially considering the complexities introduced by structures containing pointers to such memory. Adopting a systematic approach, akin to what one might find in object-oriented languages, by implementing functions that act as creators, modifiers, and destructors for your data structures, can be quite beneficial.
@brendanreeves9645
@brendanreeves9645 Жыл бұрын
Your videos are such lifesavers -- thank you!
@naboulsikhalid7763
@naboulsikhalid7763
one time explained, onetime understood. Thank you a lot
@raptoress6131
@raptoress6131
This is great, I found exactly what I was looking for
@thomasmarczi7345
@thomasmarczi7345 Жыл бұрын
Great video! Thank you so much, it helped a lot! Was having a hard time figuring out what needs to be used to assign my string value to char* property in struct. For some reason array[2].description = "string" overwrote the description property for array[0] and array[1] as well, with the same value. Stackoverflow and other forums didn't help, you did.. it's the strcpy that is needed here!
@_karf_
@_karf_ Жыл бұрын
Your video is the answer to all my questions, thank you <3
@juanmacias5922
@juanmacias5922 Жыл бұрын
Such a good video, soooooooo much info!
@fifaham
@fifaham Жыл бұрын
Thank you Kevin, that was helpful.
@thanhcong1349
@thanhcong1349 Жыл бұрын
Thanks for your helpful tutorial video.
@towtruckn
@towtruckn Жыл бұрын
Kevin; these are great videos. Just a question about freeing memory; is it possible to declare the size of the memory for the description variable inside the struct definition. In this way the free() function would only have to be called once when freeing the memory for any Point variable.
@dimitrioskalfakis
@dimitrioskalfakis Жыл бұрын
very nice. simple and useful.
@norbertracz1009
@norbertracz1009 Жыл бұрын
Thaks!
@yue7507
@yue7507 Жыл бұрын
Thank you!
@ramakrishna4092
@ramakrishna4092 Жыл бұрын
Hi sir one question here we can use -> operator there also like (array+2)->y=3; can you pls reply to me whether it's right or wrong....
@HoangNguyen-nz4xe
@HoangNguyen-nz4xe
Hi, i have a question: while allocating memory, i saw lots of people doing this (int*)malloc(...) is it necessary or just nice to have. Does it cause any issues? Thank you.
@Hackathons-wf1lg
@Hackathons-wf1lg Жыл бұрын
where did you learn how to program in C so well? Also thoughts on CPP?
@mikehibbett3301
@mikehibbett3301
I've been designing embedded systems for 35 years now, and I've never had to use dynamic memory, or floating point datatypes. I'm curious if anyone else had the same experience? I've been on a few architecture design reviews where I've had some pushback, but we ended up without needing malloc.
@moncho3115
@moncho3115 Жыл бұрын
esta genial el video
How To Return A String From A Function | C Programming Tutorial
13:51
Portfolio Courses
Рет қаралды 15 М.
Dynamic Memory Allocation | C Programming Tutorial
31:51
Portfolio Courses
Рет қаралды 80 М.
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 10 МЛН
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 25 МЛН
Structs in C | What you Need to Know
24:39
Caleb Curry
Рет қаралды 9 М.
Dynamically Allocate A 2D Array | C Programming Tutorial
15:58
Portfolio Courses
Рет қаралды 34 М.
Read CSV File Data Into An Array Of Structs | C Programming Example
11:05
Portfolio Courses
Рет қаралды 41 М.
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 58 М.
why do void* pointers even exist?
8:17
Low Level Learning
Рет қаралды 344 М.
How To Return An Array From A Function | C Programming Tutorial
13:01
Portfolio Courses
Рет қаралды 64 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,1 МЛН
Dynamic Memory with Malloc - Everything you Need to Know
13:51
Caleb Curry
Рет қаралды 8 М.
Demo: Iteration and arrays, uninitialized values, enums
59:38
Jonathan Blow
Рет қаралды 39 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 10 МЛН