Although the code is working, is has a severe and subtle problem: when allocating memory for a node, a wrong size is used, sizeof struct node *, which is 4 bytes (the size of a pointer).
The structure node itself is larger than 4 bytes, so when an element is created and initialized, the heap is corrupted. The program works because the memory is leaked (no free is performed), but in a serious application, this bug would create crashes and would be nearly impossible to find.
it would be great if you could explain your code also ... i mean like step wise how it works ... it would help me very much to understand how linked list works ...
This video is harmful. The code is totally wrong w.r.t. several points:
- Casting the result of malloc is useless.
- Allocated structs are of the wrong size.
- It is a miracle that its ultimate for works, the last pointer is not guaranteed to be NULL.
I was surprised as hell that his code actually does what he expected.
Please do not use youtube to learn programming, buy K&R.
quentinism 1 week ago
Although the code is working, is has a severe and subtle problem: when allocating memory for a node, a wrong size is used, sizeof struct node *, which is 4 bytes (the size of a pointer).
The structure node itself is larger than 4 bytes, so when an element is created and initialized, the heap is corrupted. The program works because the memory is leaked (no free is performed), but in a serious application, this bug would create crashes and would be nearly impossible to find.
petremarianalin 1 month ago
after the first for loop add
(clist--)->ptr= NULL;
to make the code work
BambooAU 3 months ago
very simple and well made video.
ganeshkamath89 5 months ago
it would be great if you could explain your code also ... i mean like step wise how it works ... it would help me very much to understand how linked list works ...
thanks
sahilgupta05 10 months ago
i made a solution for it ...
put flag at the end of your program if you have a problem..
that is in a last for loop; flag++
then put if(flag==10) { break; } so temprorary solution but for now that's all i can do :D
thanks a lot i understood this topic because of you...
anilari1991 10 months ago
thanks for your help but last code is not working :D thanks a lot
anilari1991 10 months ago
audio is too low -.-", and need some more explanation with this pgr.
l0sirissI 10 months ago
this program doesnt run not sure why
sam1209 10 months ago
improve the voice sir
onlysingleidentity 1 year ago 2