Understanding the Dangling Pointers
ฝัง
- เผยแพร่เมื่อ 25 ส.ค. 2024
- Data Structures: Understanding the Dangling Pointers
Topics discussed:
1) What is a Dangling pointer?
2) How to avoid the Dangling pointers?.
3) Examples of Dangling pointer.
4) Segmentation fault.
C Programming Lectures: goo.gl/7Eh2SS
Follow Neso Academy on Instagram: @nesoacademy(bit.ly/2XP63OE)
Follow me on Instagram: @jaspreetedu(bit.ly/2YX26E5)
Contribute: www.nesoacademy...
Memberships: bit.ly/2U7YSPI
Books: www.nesoacademy...
Website ► www.nesoacademy...
Forum ► forum.nesoacade...
Facebook ► goo.gl/Nt0PmB
Twitter ► / nesoacademy
Music:
Axol x Alex Skrindo - You [NCS Release]
#DataStructuresByNeso #DataStructures #DanglingPointer #Pointer
This channel is a holy grail of C tutorials, I am so grateful I found you. Your explanations are clear and also show you have deep understanding of what you talk about.
Damn..I don't get why your channel isn't famous yet...I refer your Vedios for almost everything including ADE.....but don't give up...! Keep at it and you'll be shining under the blue sky some day...
Your explanations are pretty good ! They are clear , concise , and thorough . You have all the key information that a lot of other CS channels are leaving out ! Thank you .
dude I used to wat you 5 years ago and really apprecite you man, you're just amazing,
you taught me computer architecture so well that I got deep level understanding of how computers actually work and also successfully build my own 4 bit computer from a breadboard and also my own seven segment display
Thanks bro Dangling pointer is asked in so many interviews. Finally i can answer it with full clarity.
Best video ever made 🔥🔥,black screen also reduces the eye strain .love u sir
Thank you, I understand English less which is why I am having a little trouble coding from these videos but I keep trying. I'm from Bangladesh 🇧🇩
Keep trying brother...
Keep trying brother....
Very good...try to infinity
Thank you so much, for so many days i was searching internet for segmentation fault but i could not understood it clearly you made it so clear thank you 🤩
thank you for all you are doing sir
sir we want such tutorials on python too...
Thank you so much. Really Neso Academy is best one for learn. You always trying to teach with full of clarity not just for cover the topics.
what i understood is that the variable inside the local function gets dealocated from the stack automatically by the compiler , so returning the pointer of a dealocated memory location makes it a dangling pointer , i hope i userstood it right ? and thank you so much
Beauty in the way you teach 💖
great explanation!
Faster than the notification! Haha!
Thanks for that.. I was never know about dangling pointer 😇. after watching this This is very helpful to me
Yah same
Thank you for the explaination, but as I try to recompile the same examples(example2) the compiler only gives me a warning for returning a local address but the program runs normally(no segmentaion fault Error),
does this means that new compilers(GCC) are optimized to avoid dangling pointers or I'm missing something ?
My code:
#include
#include
int* CreatInt(int var)
{
int I = var;
return &I;
}
int main(void)
{
int *ptr = NULL;
ptr = CreatInt(10);
printf("ptr contains: %d
", *ptr);
return 0;
}
The output:
program.c: In function 'CreatInt':
program.c:79:2: warning: function returns address of local variable [-Wreturn-local-addr]
return &I;
^
GCC_EXIT_CODE: 0
ptr contains: 10
Me too!
same here
Wow great explanation thanks man 👏👏🙏
I didn't get any warning about fun() returning a address of local variable in Turbo C++ compiler and my program runs successfully. But when I tried to run it in VS code program didn't run at all and throws a warning " warning: function returns address of local variable".
great explanation thank you so much
Thank You Sir
it helps me so much
Use static int to avoid the problem.
Yes because static variables remains till the program execution
Best explaination
Awesome explanation yarrrr
This was very new..thanks sir
Thank you!
why do we use free() if it causes dangling?
When I tried to execute the second example's program for dangling pointer in my pc, it ran without any errors. I also got the correct output as 10. I did get a warning about the fun() function returning a address of local variable but that's it. How is this possible?
I have same problem in But I didn't get any warning about fun() returning a address of local variable in Turbo C++ compiler. But when I tried to run it in VS code program didn't run at all and throws a warning " warning: function returns address of local variable".
Thank u
Why int * fun() is used isn't it a function pointer?
Thanks sir
In example2 output is 10
How to use a function pointer in struct?
Really helpful 👏
Thanks
Local variable 의 주소를 반환할 때 댕글링 포인터로 인한 세그멘테이션 폴트 발생
Excellent work...!!
love you bro
Kya dangling pointer us memory ko point to krra h vo us memory ko use kr skta h na aur value assign krke print kraya to horra h codeblocks pr .... How say 1000 memory is not exist *p still point so we can use it???
Awesome!!!
You're amazing !
i am not getting segmentation fault but getting the num value printed as 10 can u help me out
Same 4 me..
The thing is that you may get segmentation fault when you deal with the return address of local variable.I am sure you might be getting warning messages.It is not advisable to use this method.It might work for some cases while it may not work for other cases...its better to avoid it.
at 4.25, what if we define "num" as static int? then in my compiler, it works without warning.
scope of the static variable is throughout the program.
visual studio 2019 could not high light this fault its execute successfully
when will control system videos come?
2:43 sir what if we skip free(ptr) ????
I think the memory allocated to 'ptr' is still not yet freed.
Even though 'ptr' will not point to any memory location(i.e NULL pointer) but the chunk of memory allocated using malloc function will be inaccessible due to not being freed.
There will be no error while compiling or running the program but it is a bug.
So, free(ptr) is necessary.
Is this for java?
data structure with C
Goood bro
2:13
2:48
4:50
2:11
🥰🥰😍😍😍🤩😘
dude when I tried it it gave me waning at compile time but gave the right answer and right memory address...
```
#include
#include
int *haha () {
int num = 554;
printf("in hah->%d:%u
", num, &num);
return #
}
void main () {
printf("%d: %u
", *haha() , haha());
}
```
don't read from geeksforgeeks just come here.. or use trusted books