Understanding the Dangling Pointers

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 68

  • @matousvondrak3461
    @matousvondrak3461 Год назад +18

    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.

  • @kanishkgupta5015
    @kanishkgupta5015 2 года назад +8

    Thanks bro Dangling pointer is asked in so many interviews. Finally i can answer it with full clarity.

  • @bossysmaxx3327
    @bossysmaxx3327 Год назад +3

    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

  • @edwardmacnab354
    @edwardmacnab354 2 года назад +7

    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 .

  • @anshuraj9610
    @anshuraj9610 3 года назад +6

    Best video ever made 🔥🔥,black screen also reduces the eye strain .love u sir

  • @Tarun_Kotagiri
    @Tarun_Kotagiri 4 года назад +25

    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...

  • @aviroxi
    @aviroxi 3 года назад +10

    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 🤩

  • @tanviralam9798
    @tanviralam9798 4 года назад +33

    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 🇧🇩

  • @pk_officl
    @pk_officl 3 года назад +1

    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.

  • @kingdey9136
    @kingdey9136 4 года назад +5

    thank you for all you are doing sir
    sir we want such tutorials on python too...

  • @yutaitadori7318
    @yutaitadori7318 3 года назад +3

    Beauty in the way you teach 💖

  • @tahaanass3097
    @tahaanass3097 3 месяца назад

    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

  • @nishyu9101
    @nishyu9101 2 года назад +1

    great explanation!

  • @gulabchandgupta5486
    @gulabchandgupta5486 Год назад

    Wow great explanation thanks man 👏👏🙏

  • @kunalsoni7681
    @kunalsoni7681 4 года назад +1

    Thanks for that.. I was never know about dangling pointer 😇. after watching this This is very helpful to me

  • @amiral3187
    @amiral3187 2 года назад +3

    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

  • @sallaklamhayyen9876
    @sallaklamhayyen9876 2 года назад

    great explanation thank you so much

  • @HelloWorld40408
    @HelloWorld40408 Год назад

    Thank You Sir

  • @mdkalimullahzakir
    @mdkalimullahzakir 6 месяцев назад

    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".

  • @sureshsingh9880
    @sureshsingh9880 2 года назад

    it helps me so much

  • @akshadabhapkar8944
    @akshadabhapkar8944 3 года назад

    Awesome explanation yarrrr

  • @vivelafootball4835
    @vivelafootball4835 Год назад

    Best explaination

  • @nithyashreenaidu8357
    @nithyashreenaidu8357 4 года назад

    This was very new..thanks sir

  • @emkcoryo8742
    @emkcoryo8742 4 года назад +6

    Faster than the notification! Haha!

  • @oggy107
    @oggy107 3 года назад +2

    Use static int to avoid the problem.

    • @prog2597
      @prog2597 2 года назад

      Yes because static variables remains till the program execution

  • @abhishekm1903
    @abhishekm1903 4 года назад +1

    Excellent work...!!

  • @ritikashishodia675
    @ritikashishodia675 3 года назад

    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???

  • @shantanukulkarni8883
    @shantanukulkarni8883 Год назад +1

    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?

    • @mdkalimullahzakir
      @mdkalimullahzakir 6 месяцев назад +1

      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".

  • @sameeruj
    @sameeruj 3 года назад

    Thank you!

  • @sumainakyasar8857
    @sumainakyasar8857 2 года назад

    why do we use free() if it causes dangling?

  • @47-6F-64
    @47-6F-64 4 года назад

    You're amazing !

  • @tarunpatel1457
    @tarunpatel1457 4 года назад

    Really helpful 👏

  • @shourjyajitmaiti2490
    @shourjyajitmaiti2490 4 года назад

    when will control system videos come?

  • @KUNALSINGH-zk8su
    @KUNALSINGH-zk8su 4 года назад

    Thanks sir

  • @md.nahidulalamchowdhury9568
    @md.nahidulalamchowdhury9568 2 года назад

    Awesome!!!

  • @dileepcheekala2617
    @dileepcheekala2617 Год назад +1

    In example2 output is 10

  • @pawansahu5265
    @pawansahu5265 4 года назад

    Thanks

  • @원형석-k3f
    @원형석-k3f 3 года назад +1

    Local variable 의 주소를 반환할 때 댕글링 포인터로 인한 세그멘테이션 폴트 발생

  • @usmanhaider4653
    @usmanhaider4653 Год назад

    How to use a function pointer in struct?

  • @prashanthreddy5959
    @prashanthreddy5959 4 года назад +2

    i am not getting segmentation fault but getting the num value printed as 10 can u help me out

    • @pradhoshss8281
      @pradhoshss8281 4 года назад +1

      Same 4 me..

    • @ShubhamMishra-mz4zw
      @ShubhamMishra-mz4zw 4 года назад

      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.

  • @zeeshansadiq9069
    @zeeshansadiq9069 4 года назад +1

    visual studio 2019 could not high light this fault its execute successfully

  • @jacklaughter1219
    @jacklaughter1219 4 года назад +2

    at 4.25, what if we define "num" as static int? then in my compiler, it works without warning.

    • @ayushshreshthi3891
      @ayushshreshthi3891 4 года назад +3

      scope of the static variable is throughout the program.

  • @letsroastbro7545
    @letsroastbro7545 3 года назад

    2:43 sir what if we skip free(ptr) ????

    • @andistheinforitbutso7513
      @andistheinforitbutso7513 2 года назад +1

      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.

  • @seaofknowledge2477
    @seaofknowledge2477 3 года назад

    Is this for java?

  • @srikarrepaka5023
    @srikarrepaka5023 3 года назад

    2:13
    2:48
    4:50

  • @LearnwithAnas
    @LearnwithAnas 4 года назад

    Goood bro

  • @arghya.7098
    @arghya.7098 3 года назад

    2:11

  • @48_prasenjitmondal6
    @48_prasenjitmondal6 4 года назад

    🥰🥰😍😍😍🤩😘

  • @Sakthibalankk
    @Sakthibalankk Год назад

    love you bro

  • @bossysmaxx3327
    @bossysmaxx3327 Год назад

    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());
    }
    ```

  • @techxplorerxxx
    @techxplorerxxx 3 года назад

    Why int * fun() is used isn't it a function pointer?

  • @andistheinforitbutso7513
    @andistheinforitbutso7513 2 года назад

    don't read from geeksforgeeks just come here.. or use trusted books