Just like professor Feynman said if you understand something well enough you’ll be able to explain it in the most simplest way.and that’s exactly you’ve done. Thank you for making this difficult topic understandable!!!
Exactly and we all remember the teachers who did and did not! The best teaching videos in programming do not have disturbing background noises e.g. music and only have relevant information on the screen.
I went in with no expectation, I finished with complete understanding of what I should be doing, and also a slightly better idea on pointers/array. Thanks a bunch, appreciate your work greatly.
This has been the most easy -to-understand tutorial ever since. Thanks a lot. Just a little something : on function free2dIntArray() we shouldn't include the third parameter dim2 on the function's prototype.
I know I'm a bit late to the party but goddammit that explanation is so good. pleace don't stop doings vids like this you've made a difference in someone's life
Nice explanation! However there's an optimized way to allocate a 2d array int **p = (int **)malloc(rows * sizeof(int *)); p[0] = (int *)malloc(rows* columns * sizeof(int)); for (i = 1; i < rows; i++) { p[i] = p[i - 1] + columns; } free(p[0]); free(p); In this case, a single block of memory is allocated and rearrange the pointers to form an array. This is computationally better for a few reasons: 1. The allocation engine does not perform as many allocations as before. 2. As opposed to the conventional implementation, there's no extra bytes between rows to keep count of the memory blocks. That means the final 2d array is represented in a continuous memory block. Therefore, there's no need to make large moves between those positions in the memory. 3. free() is called twice only. The conventional implementation depends on the 'rows' size.
Can you please make complete knowledge of c/cpp, You are way of teaching so good and you really get us into deep which really i want !! Thanks for this video 🤠
I finally understood why it works like that thanks to you :) Just got a question, in the freeing part (the correct one) wouldn't it be the same if I didn't pass dim2 as a parameter, since it's not needed for deallocating the memory?
Actually the true dynamic 2d array can be allocated with a pointer to array. Just do `int (*arr)[dim2] = calloc(dim1, sizeof *arr);`. And that's all. Just remember to call `free(arr)` at the end.
Thanks for commenting. If you are using fixed size strings you can simply substitute with throughout this video and it will work in the same way. In this case dim1 would be the number of strings and dim2 the maximum string length, including the end of string sentinel. If you want a jagged array (strings of different lengths), you’d need to do things a bit differently. Is the latter what you had in mind?
As you say, it is not contiguously allocated 2d array: each row will be allocated to separate locations on the heap. Also, I get what you mean by lookup table: the "column array" of pointers to integers are used to "look up" each row. I wouldn't personally call it a lookup table, though. For me they (lookup tables) are a higher order construct used for a smaller set of specific applications.
It would have been nicer if you give meaningful names to parameters like instead of Dim1 Dim2 you can could have written Row and col, in video you are mentioning them as row and col why not name them the same.
Underrated video, you should be top search for c programming. It makes so much more sense to me now
Thanks!
To be honest, this is the most comprehensible explaination on youtube, thank you so much !
Just like professor Feynman said if you understand something well enough you’ll be able to explain it in the most simplest way.and that’s exactly you’ve done. Thank you for making this difficult topic understandable!!!
Exactly and we all remember the teachers who did and did not!
The best teaching videos in programming do not have disturbing background noises e.g. music and only have relevant information on the screen.
Dude is a GOAT. As a grad student taking a CS class (non cs major) this has made it extremely clear how to allocate dynamic memory. Thanks!
Wow ! Great explanation, i'm french and your english is very understandable ! Thanks a lot !
I went in with no expectation, I finished with complete understanding of what I should be doing, and also a slightly better idea on pointers/array. Thanks a bunch, appreciate your work greatly.
This has been the most easy -to-understand tutorial ever since. Thanks a lot.
Just a little something : on function free2dIntArray() we shouldn't include the third parameter dim2 on the function's prototype.
Thanks for your kind words and yes you are correct.
I know I'm a bit late to the party but goddammit that explanation is so good. pleace don't stop doings vids like this you've made a difference in someone's life
perfect. the only one that explained clearly so far.
Finally some good explanation about 2D dynami array! Piece of gem! Thank you!
Great video to help shake out the cobwebs. My favorite on RUclips for the topic.
Thank you!
thank you for the effort creating this wonderful video
Very good explanation sir it's a superb video. Everyone can understand this concept without any doubt.
please you are amazing , thnks a lot and you have made my difficulties become simple for me 💯🙏🙏
man thank you so much this video I find it the best one on RUclips ♥
Very well explained , I'm glad I found your channel !
You are a good teacher, thank you!
I was struggling with this all day
thank you man, you save me from my upcoming test, thanks a lot
Very informative 🔥
Thank you, this was an approachable explanation that helped me finally understand the concepts.
best explanation , keep it going !
Best video on this topic !! Thanks alot.
Amazing explanation way more clear than my college professors
exactly what I needed :) I'm working on a small project that solves a system of user input equations and this is the core of it
Nice explanation! However there's an optimized way to allocate a 2d array
int **p = (int **)malloc(rows * sizeof(int *));
p[0] = (int *)malloc(rows* columns * sizeof(int));
for (i = 1; i < rows; i++) {
p[i] = p[i - 1] + columns;
}
free(p[0]);
free(p);
In this case, a single block of memory is allocated and rearrange the pointers to form an array. This is computationally better for a few reasons:
1. The allocation engine does not perform as many allocations as before.
2. As opposed to the conventional implementation, there's no extra bytes between rows to keep count of the memory blocks. That means the final 2d array is represented in a continuous memory block. Therefore, there's no need to make large moves between those positions in the memory.
3. free() is called twice only. The conventional implementation depends on the 'rows' size.
I feel like I don't need to know this for the problem set I'm doing, but this was very helpful regardless. Thank you!
Excellent explanation
What an explanation! Thanks a ton man.
This is a life saver. Thank you!
Thank you so much for the explanation!!
Thank you very much for this wonderful content.
amazing explanation!! Thanks alot really
Thank you so much man! This was great.
TE AMO GRACIAS !!!
B E A U T I F U L EXPLANATION
Can you please make complete knowledge of c/cpp, You are way of teaching so good and you really get us into deep which really i want !!
Thanks for this video 🤠
Thanks for your kind words Zuned. I'll try and upload some other material soon.
@@jatinthebox8574 willwait for more.
Clearly understood! Thank you sir.🙇
this video is so good!Thanks!
You're the best
perfect video
This was a great video!
Thanks for taking the trouble to comment - appreciated.
great video
Thanks!
why is (int**) debatable? is there something wrong with using it? thanks!
You just do not need it, but I think it makes the code more readable. I think it reminds people of Java, which they do not like, but I do 🙂
thanks a lot that was quite helpful.
you're a fuckin lifesaver, man
This was gem
I hate c keeps telling there is a leak and when i try to free that memory thats leaking i got an invalid free
thanks bro!
I finally understood why it works like that thanks to you :)
Just got a question, in the freeing part (the correct one) wouldn't it be the same if I didn't pass dim2 as a parameter, since it's not needed for deallocating the memory?
Yep, you are right. Well spotted.
thank you sir!
i love this
thank you sir.
Actually the true dynamic 2d array can be allocated with a pointer to array. Just do `int (*arr)[dim2] = calloc(dim1, sizeof *arr);`. And that's all. Just remember to call `free(arr)` at the end.
That's a really neat way of doing it. Do a video to explain how it works ? ;-)
@@jatinthebox8574 sure sir
this is the one
legend
Can you please make a video about dynamic allocation for array of strings please
Thanks for commenting. If you are using fixed size strings you can simply substitute with throughout this video and it will work in the same way. In this case dim1 would be the number of strings and dim2 the maximum string length, including the end of string sentinel. If you want a jagged array (strings of different lengths), you’d need to do things a bit differently. Is the latter what you had in mind?
why did u stop posting ? 😥
Just wasn't much interest 😔
make more videos please
Strictly speaking isn't this a lookup table not a true contiguously allocated 2d array?
As you say, it is not contiguously allocated 2d array: each row will be allocated to separate locations on the heap. Also, I get what you mean by lookup table: the "column array" of pointers to integers are used to "look up" each row. I wouldn't personally call it a lookup table, though. For me they (lookup tables) are a higher order construct used for a smaller set of specific applications.
It would have been nicer if you give meaningful names to parameters like instead of Dim1 Dim2 you can could have written Row and col, in video you are mentioning them as row and col why not name them the same.