Good Example of Dangling pointer. Collin please upload similar concept video for malloc, calloc and free functions.
@AtAGlimpse_UB3 жыл бұрын
I just want to say one thing. Whenever your Microcontroller gets into the infinite loop when you step up your code, that might be due to the pointer pointing to a address which is not existing.
@asafcohen35624 жыл бұрын
This is great
@1willFALL4 жыл бұрын
Could you do a video on function pointers and maybe also on FILE I/O?
@rafalzasada88264 жыл бұрын
If malloc() returns just a pointer how program know what amount of memory is allocated and can't be used for anything else? The same goes for free() function - if we pass just a pointer to it how program knows what amount of memory became available ? Pointer is just a pointer, sizeof(*p) does not work so where is that information stored about a size?
@leviengel3 ай бұрын
When using malloc. you basically request the amount of memory you need, the OS, look for that amount of memory in the HEAP region of RAM and if found the amount of memory requested, returns a pointer to the start of that chunk of memory. It is the responsability of the programer to manage and keep track of that memory. That's why when using malloc you have to cast that pointer to the size of datatype you will be using. If malloc does not find the amount of memory you require, it will return a NULL pointer. A pointer has metadata containing information of the size of memory it points to, that's how the OS knows how much memory free.
@muhammadinamulhaq36224 жыл бұрын
I've a question. If I return the address of array from a function, and use this code x = *(p+3); will it return the right element at that location? or system might use that memory to change the contnts and I might get a wrong value stored in that memory?
@kolhatkarchinmay4 жыл бұрын
No it will cause segmentation falut. As memory location assigned to arr[ ] is already removed out of stack. So p already containing invalid location. So doing any operation with p is invalid.
@muhammadinamulhaq36224 жыл бұрын
@@kolhatkarchinmay but p has a memory address and I'm pointing to some value at address *(p+3) so it should be valid. Question is if the data Will be same or as the arr is not there anymore and we've not used malloc so the system might usw the memory and put some other data.
@joaquinortiz2794 жыл бұрын
@@muhammadinamulhaq3622 as before mentioned, it will cause a segmentation fault. Don't worry about the data value when you are pointing to undefined memory addresses