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
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 🤩
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
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
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".
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".
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???
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.
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.
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()); } ```
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 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, 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. Really Neso Academy is best one for learn. You always trying to teach with full of clarity not just for cover the topics.
Beauty in the way you teach 💖
thank you for all you are doing sir
sir we want such tutorials on python too...
great explanation!
Thanks for that.. I was never know about dangling pointer 😇. after watching this This is very helpful to me
Yah same
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
Wow great explanation thanks man 👏👏🙏
Is this playlist helpful for gate preposition also?
Faster than the notification! Haha!
Use static int to avoid the problem.
Yes because static variables remains till the program execution
great explanation thank you so much
Thank You Sir
it helps me so much
Best explaination
Awesome explanation yarrrr
This was very new..thanks sir
Thank you!
Really helpful 👏
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
In example2 output is 10
Local variable 의 주소를 반환할 때 댕글링 포인터로 인한 세그멘테이션 폴트 발생
How to use a function pointer in struct?
Thanks sir
Excellent work...!!
You're amazing !
Thanks
Awesome!!!
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".
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".
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???
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.
love you bro
2:13
2:48
4:50
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.
which font used in slide ?
when will control system videos come?
visual studio 2019 could not high light this fault its execute successfully
2:11
Is this for java?
data structure with C
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.
Goood bro
🥰🥰😍😍😍🤩😘
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
Why int * fun() is used isn't it a function pointer?