Thank you literally thank you so much ma'am for introducing me with the concept of dangling pointer. I was googling from 1 hour that " although I have free the memory from heap but the pointer is still storing the address of that memory block. Why is it so ? " And 1 hour later..... I came across your video which helped me alot literally a lot. Thank you again and again.
Basically in your program there are 3 components code, stack, heap. The programming language code is complied by a compiler to machine code. The code can aceess variable directly from the stack but the function such as delete will be allocated in the heap. The heap has a pointer in the stack so the stack can be the median where the code can access the heaps memory. Stack has static(size) memory allocation while heap has dynamic(size) memory allocation.
bro just dont like and leave without watching full video bcoz the average view duration of video will decrease and it will be an negative impact on the channel.....🙂🙂as youtube doesnt consider number of likes it only counts average view duration😉
The practice questions of notes links and previous notes links are also not working. Please rectify it bhaiya and thank you very much for such high quality content.
Code is here: #include using namespace std; int main(){ int a = 1; // stored in stack int* p = new int(); // allocate memory in heap *p = 1; // 'p' is a pointer that is stored in stack but the value is stored in heap delete(p); // deallocate mmemory in heap but 'p' still uses bytes in stack p = new int[4]; // 'p' can be reused delete[] p; //delete array p = NULL; // delete pointer value return 0; }
Bhiya timetable ke hisaab se kuch topics miss ho gye h... Stack and heap ke pehle bhi kuch topic the... Aur pointer bhi kaafi vast topic h... Please take a look.. And thnx for your team aman bhiya your team is doing a great job🙂🙂
Don't deallocate too soon Only deallocate memory when you are truly finished with that memory. If you have more than one pointer to a chunk of memory, then deallocating that chunk makes all pointers to it stale; they are pointing to memory that you are no longer allowed to use. Those pointers are called dangling pointers. Watch out: no automatic deallocation in the heap Some languages, such as Java, use garbage collectors that periodically go through the heap and recycle chunks of memory that are not being used. That does not happen in a C++ program. If you lose all pointers to a chunk of memory without deallocating that memory then you have a memory leak. Your program will continue to own that memory, but has no way of ever using it again. A very small memory leak is not a problem. But if a program allocates a lot of memory and never deallocates it, the program's memory footprint will grow and grow. When your program stops, all of the memory that it owns is automatically recovered by the operating system. So a memory leak is only relevant while a program is running; it does not affect the system after the program stops.
your videos are amazing ,it is really helping me allot ,now i can do coding,because i can think of some approach ,you people taught us how to think in coding,big thanks from my end
Are the practice questions mentioned in the end of the notes pdf not meant to be some links?? Because they are highlighted blue and underlined but they are just text only and there is no link attached to them and basically seem like dangling pointers. Lol
❗ Error or Doubt ❗ 1:06 Can num1 and num2 be accessed from main from function ? No Can a, b, sum be accessed from add function ? -No- Yes, with help of pointers
i had the same doubt ... that way any variable is a global variable na?.......it can also be the case that as stack memory is not permanent and can be popped its not good to take it as a global variable declaration space.
What's the point of storing a variable in heap of its pointer gets stored in stack? We are anyway using the stack memory when storing the pointer. How does it help with the code?
maybe we are doing so because now as we are just storing the pointer or address in stack then we are using very less space in stack and actual thing that we want to store is in heap! This way we are saving the memory of the stack which is Limited.
added question link for this and previous lecture on my github : github.com/rahulsain3000/CPP-DSA/blob/master/resources.txt other are in lecture 14 in phase 1 folder check out
@@_rahulsain Hello sir can you please tell how to make Mega.nz downloader which can work without Vpn , Cause the ones i found on github are not working properly, Also the Mega Downloader doesn't works.
@@_rahulsain But this link has questions in C. Where to practice the C++ questions from ? Pointers can still be done from C one but DMA has completely different format in both the languages.
When we deleted the array created in heap using delete[]p; And then assigned NULL to pointer p , So shouldn't the value of p become zero ? It is still 400. (Maybe you forget to do so or whether i am wrong, pls correct me)
Bhaiya, Course ki timeline ke hisaab se strings ke topics miss hogye h, and pointers bhi kaafi vast topic hai, jitna aapne padhaya h uske alawa bhi pointers me kaafi kuch hai, please bhaiya please vo sab bbi sikha dijiye
Hello my fellow online classmates can anyone please tell me that the questions given at the end of pdf contain links or are simple texts and if they are links then how to open it???
Anyone reply plz... 1.pointer variable ka size kitna hota 2. At one place she deallocate by typing "delete(p)" and another place"delete[ ]p".So i think these are two different syntax And when we use first and when second
delete(p) we use when we have to deallocate memory of a variable or pointer from heap . delete[ ]p we use when we have to deallocate memory of an array from heap .