Pointers as function returns in C/C++

  Рет қаралды 282,502

mycodeschool

mycodeschool

Күн бұрын

Пікірлер: 239
@mycodeschool
@mycodeschool 11 жыл бұрын
Hi Mustafa, Please watch the complete video. That's the whole point that has been explained in the video that you cannot return pointer to a local variable. I think because you knew the concept already and you have this opinion that one cannot learn programming on KZbin, you got angry and skipped at 9:00. :)
@prankita107
@prankita107 5 жыл бұрын
You are awesome . Make more videos and bless us please.
@adityaojha2701
@adityaojha2701 3 жыл бұрын
Today everyone learns on KZbin and not only programing but everything. MyCodeSchool took initiative of making this highly valuable content during a time when people were using 2G. Then also your content quality is way better.
@mycodeschool
@mycodeschool 11 жыл бұрын
Yes, printf is a library function. So, a stack-frame will be allocated for printf also. Sorry, i did not show it in my simulation. stack frame is allocated corresponding to each call of a function. So, if there are multiple calls to printf in the same function. stack frame will be allocated and de-allocated multiple times corresponding to each call of printf.
@everything9118
@everything9118 6 жыл бұрын
This man is lit. U teach so well. I have been in touch with c since 4 years, still didn't know these things. U r awesome!
@user-yg2gw4je8d
@user-yg2gw4je8d 8 жыл бұрын
This is an excellent series. In my view, your extended explanation/demonstration of pointers is especially good. Thank you so much for doing this.
@gijimbo1337
@gijimbo1337 5 жыл бұрын
1st, I know this video was posted 6.5 years ago but good content is good content and is still valid today. What I'd like to add is that "delete ptr" should be used when we're done using it. After that, "ptr = nullptr" should also be used so we don't end up with a dangling pointer.
@soham2732
@soham2732 3 жыл бұрын
Hiiii I am from 2021 😂
@KT22672
@KT22672 Ай бұрын
2024 Still valid Still goated
@shivamverma9447
@shivamverma9447 4 жыл бұрын
This holy and sacred video cleared all the concepts...............
@amandeepsingh2314
@amandeepsingh2314 8 жыл бұрын
you are awesome... great tutorial.. its really helped me a lot. you are doing a great job.
@vasanthidevipaneerselvam48
@vasanthidevipaneerselvam48 5 жыл бұрын
Excellent explanation of pointers... No words to tell...now got clear idea of all concepts in pointers ...watch all videos on pointer
@ozzyfromspace
@ozzyfromspace 5 жыл бұрын
Wow, I don't know how you did that, but you made me understand. That's super hard to do lol 😅 You're amazing man, thank you!
@samvaidya1987
@samvaidya1987 5 жыл бұрын
Every video has a ton of information. Very humbling. Thanks a ton!!
@elementallobsterx
@elementallobsterx 5 ай бұрын
Incredible explanation
@rajdeepkhandelwal1653
@rajdeepkhandelwal1653 5 жыл бұрын
all I can say "Thank You for this pointer tutorial".(Awesome explanation)
@mycodeschool
@mycodeschool 11 жыл бұрын
Thanks Bharath !! yeah, may be i should always write a free. If you see program will anyway finish execution after print where we are using the pointer to access memory. But anyway, its a good practice to write free explicitly.
@joshidikshya6183
@joshidikshya6183 4 жыл бұрын
Could you please explain where should free() be placed? Writing free on main will create a segmentation fault.
@satwaghole
@satwaghole 11 жыл бұрын
@kewlpint: Yes.printf() is considered as another function call and separate stack frame is allocated for it. Nice question. @mycodeschool: You r doing gr8 job boss.Go ahead..
@ankukumar7874
@ankukumar7874 4 жыл бұрын
I don't have words to describe how excellent you are.
@naboulsikhalid7763
@naboulsikhalid7763 5 ай бұрын
programming C at the best. Born to teach elegantly. Thank you
@dogdutyascetic
@dogdutyascetic 11 жыл бұрын
Simply brilliant. The explanation of using the heap as a way to pass values down the calling stack is brilliant.
@1990idris
@1990idris 9 жыл бұрын
thank you very much. i read some books about c, but your explanation is the best. because you explain step by step.
@zarifahmed1024
@zarifahmed1024 5 жыл бұрын
I just paused the video in the middle to say that you my brother you are awesommmeeeee!!!!! Take love
@maheshrokade5
@maheshrokade5 5 жыл бұрын
Bro.... thank you so...much.. your teaching is awesome😊 , no one actually touch such concepts but..you did...
@cajhdz
@cajhdz 2 жыл бұрын
Thank you very much, my mind was crashed because I didn't know the root cause of this behaviour You have a great! channel to learn from
@anondoggo
@anondoggo 5 жыл бұрын
I never understood cs this well before. Thank you!
@hamzaahmad9489
@hamzaahmad9489 6 жыл бұрын
Since your playlist tells almost everything a beginner needs to know about pointers . Kindly rename it with "All you need to know about pointers" . I couldn't find your video easily although it was much better than all videos I saw on pointers.
@PrayingForYourWellBeing
@PrayingForYourWellBeing 7 жыл бұрын
This guy is seriously amazing, no words to describe his ingenuity !!!
@rugri
@rugri 3 жыл бұрын
Best explanation ever! Thanks
@fyionyoutube
@fyionyoutube 2 жыл бұрын
At @6:40 time, you have compiled the code successfully, but in my compiler, it is having segmentation fault, as it is being a Darlington pointer. Please share your answer.
@user-rt2fm4cp1
@user-rt2fm4cp1 2 жыл бұрын
Do you know how to correct this error ? I am also getting segmentation fault after writing exactly the same code in the video....You know any solution to it ?
@conquerorcj26
@conquerorcj26 6 ай бұрын
I watched from the first video in this playlist upto here in one watch..This playlist made me relise and gave a realaly good uunderstanding also cleared lotta doubts on a project i did using dynamic memory allocation.Thanks a lot
@mycodeschool
@mycodeschool 11 жыл бұрын
Thanks a lot :)
@ZeriAi
@ZeriAi 3 жыл бұрын
I've been watching at least one of your videos each day Thank you for your content
@aloyrs
@aloyrs Жыл бұрын
This video basically explains why there is error when using pointers on the stack as data can be deallocated , however in when using pointers in the heap data has to be explicitly deallocated or overwritten using free() which is handled by the programmer, so there will be no accidental deallocation of data unlike in the stack
@ShubhamSharma-qy8ti
@ShubhamSharma-qy8ti 7 жыл бұрын
Great tutorial sir. I look forward to learning a lot from you.
@pronoob4890
@pronoob4890 3 жыл бұрын
This cleared my concept. Thanks a lot.🤗🤗🤗🤗
@cankocak1068
@cankocak1068 Жыл бұрын
Great explanation! This video shows why we should return a pointer from the function using dynamic memory allocation.
@sankarnampoothirikm3930
@sankarnampoothirikm3930 8 жыл бұрын
wow cooooooooool i was serching this for days u r the only one who cleared my doubt (my doubt was about array returning) you r god
@devesh5955it
@devesh5955it 11 жыл бұрын
Rocking Dude :), The concept regarding Top to bottom and bottom to top of the stack is cristal clear... Thank a lot Bro :)
@bharathslip9
@bharathslip9 11 жыл бұрын
Excellent video demonstration about usage of pointers. Please release the memory which is dynamically allocated by Malloc in the heap.
@clintonahong
@clintonahong 10 жыл бұрын
Actually it seems very fast to learn the concepts.Although i listen slowly with pause and play again and again thinking all about the int* add(int *a,int *b).Now i finally understand the underlying concepts .Thanks to mycodeschool for such valuable lectures .
@sunandachowdhury1455
@sunandachowdhury1455 Жыл бұрын
Can you kindly explain why they used int *add? Don't we write the name of function at that place?
@rohithbhandari7836
@rohithbhandari7836 6 жыл бұрын
You are just amazing. I have no words to say.Excellent teaching skills.
@Protick1994
@Protick1994 6 жыл бұрын
Very nice brother, nice explanation. Thanks to you from bottom of my heart. Keep up the good work, best wishes
@rashigupta1813
@rashigupta1813 4 жыл бұрын
Man! Thanks a ton. These videos are so easy to understand
@hardikraj9469
@hardikraj9469 5 жыл бұрын
From where did you study these tehings? It would be really helpful if you could give the materials or the name of the books from where you studied the 'application memory'
@saiyaswanthreddyleagala725
@saiyaswanthreddyleagala725 4 жыл бұрын
Massive respect !!
@joecort9890
@joecort9890 5 жыл бұрын
What a master I was struggling with a linked list, and I thought it was something due to some of this, and I was right. Thank u.
@aptitudepointiit-bhu5358
@aptitudepointiit-bhu5358 2 жыл бұрын
Amazing Explanation !! 💛
@jdschlichting
@jdschlichting 5 жыл бұрын
This was very easy to follow along with. Thanks!
@arafamahmood
@arafamahmood 11 жыл бұрын
u explain very nicely!thanx for the lesson
@thestarinthesky_
@thestarinthesky_ 4 жыл бұрын
You are too amazing! you are extraordinary amazing! Google is lucky to have you. Wish you the best in the world! Thank you.
@sairajdas6692
@sairajdas6692 5 жыл бұрын
Simply terrific explanation!!
@muhammadnaveed7953
@muhammadnaveed7953 2 жыл бұрын
Excellent demonstration on pointers and memory..
@utkarshkathuria2931
@utkarshkathuria2931 3 жыл бұрын
Hi, the code you showed in the video doesn't work
@viithalbhat5640
@viithalbhat5640 3 жыл бұрын
Amazing. Superb. Subtle. Love you.
@sameerabanu329
@sameerabanu329 3 жыл бұрын
Thanks for your tutorial. It is helping me alot. Please start posting more videos.
@alexanderschmidt8976
@alexanderschmidt8976 8 жыл бұрын
best possible explained, THANK YOU!
@SushrutKanetkar
@SushrutKanetkar 11 жыл бұрын
Excellent explanation man ! Thank you very very much !
@vidyarthi3944
@vidyarthi3944 4 жыл бұрын
Great explanation.❤❤❤❤❤❤❤❤❤❤❤💚❤💖💖💓
@drnovice612ita
@drnovice612ita 8 жыл бұрын
Illuminating explanation
@timoteisatmarean7391
@timoteisatmarean7391 7 жыл бұрын
Subscribed because of this video. Thanks!
@inderpreetsingh2658
@inderpreetsingh2658 7 жыл бұрын
I had a doubt.. at 13:50 why did you remove return '&'c and wrote return c; what would have happened if we still used & operator?
@mohamedamrali1993
@mohamedamrali1993 7 жыл бұрын
I went down in the comment section, just to check if someone else had the same thought. I am thinking it's probably just a style thing... not sure if there was a real purpose for it. I am trying to think of it carefully.... If any other experienced coder out there could confirm with us, it would be highly appreciated!! Thanks
@aminemarzouki794
@aminemarzouki794 7 жыл бұрын
+MoHAMED Ali No It's not a style thing. At the first time, he wrote INT c = *a + *b; so if we need to return the ADDRESS of c we must precede it with &. That's why he wrote return &c; After that, he changed the variable c of type int, to a pointer to int which is int*. Now we have int *c = ... If you want to return the address of c, you simply return c, because c now is NOT an int, it is a pointer to int. So return c will return the address of integer c, if you did return &c however, you'll return the address of the pointer c ( int*** c).
@Reflectives
@Reflectives 4 жыл бұрын
@@aminemarzouki794 I didn't go down to docs for that, but if I got it right "*c =" means put the result to this memory location. Otherwise it would go to the stack again
@sandeepkumawat4982
@sandeepkumawat4982 4 жыл бұрын
huhhh,,,,i got tired of writing positive feedback for this man in every video...but still i feel these appreciations are not much for his skills ^_^
@shezijalal1774
@shezijalal1774 10 жыл бұрын
Awesome Explanation ! Thanks !
@mycodeschool
@mycodeschool 11 жыл бұрын
Thanks Dev !
@rashmikiranpandit8962
@rashmikiranpandit8962 5 жыл бұрын
amazing as always!
@garryharry1024
@garryharry1024 9 жыл бұрын
Amazing tutorial! Clear as always...
@vidyadherreddy2511
@vidyadherreddy2511 10 жыл бұрын
Really nice videos..simple explanation to complex concepts
@farhantanvir3073
@farhantanvir3073 11 жыл бұрын
very nice explanation. Thank you.
@MMABeijing
@MMABeijing 2 жыл бұрын
that's amazing, I can not believe it. Thank you Coach
@mayankverma5490
@mayankverma5490 4 жыл бұрын
Very valuable lesson......Thank you very much!!!!!!!
@dwivedys
@dwivedys 7 жыл бұрын
Simply brilliant tutorial. I like the way you deliver your lecture. Would like to connect with you
@sayantaniguha8519
@sayantaniguha8519 4 жыл бұрын
Watch till 6:42 for concept of *Function returning Pointer* according to *Pointer ppt for DSA KIIT Class* .
@aleeibrahim8672
@aleeibrahim8672 8 жыл бұрын
Explained pretty well!! thanks :)
@lukthi
@lukthi 8 жыл бұрын
So clear to understand, thank u @mycodeschool
@gitakujur6660
@gitakujur6660 6 жыл бұрын
Lucas Dantas . bulu
@rmarinero
@rmarinero 6 жыл бұрын
Amazing! great refresher and tutorial
@thenottakenone
@thenottakenone 10 жыл бұрын
Really really good explanation
@nalia20111
@nalia20111 10 жыл бұрын
Your videos helped me so much! Thank You !:D
@mistersz
@mistersz 10 жыл бұрын
Excellent Tutorial, Great Teacher, Thank you very much !
@kunalpanchal7751
@kunalpanchal7751 5 жыл бұрын
Thank you for Blowing my mind.....
@zacian4941
@zacian4941 4 жыл бұрын
you are a....LEGEND!
@Anddosdd
@Anddosdd 11 жыл бұрын
Exellent video,ive learnt alot my friend
@nearriver8174
@nearriver8174 11 жыл бұрын
nice! I really love this video
@anchitbhushan6172
@anchitbhushan6172 5 жыл бұрын
Can we use static pointer to integer variables to store addresses??
@vijaykumarreddyt3287
@vijaykumarreddyt3287 5 жыл бұрын
Yes we can use...as static variables are stored in static segment...the addresses of variables in this segment is unchanged until the complete execution of programme
@Naveen-ef2dg
@Naveen-ef2dg 6 жыл бұрын
Worth of Time. kudos..!!!
@ОлегТокмачев-в9ц
@ОлегТокмачев-в9ц 4 жыл бұрын
Cool! Thanks shedding light on this topic. Bless you! :)
@ramfattah211
@ramfattah211 Жыл бұрын
Thank you Harsha Suryanarayana AKA humblefool. RIP Legend.
@EngWorld-nr2ww
@EngWorld-nr2ww 4 жыл бұрын
Explained so well
@overclockinggames2419
@overclockinggames2419 7 жыл бұрын
this was great sir , a learned a new thing
@abhimanyumishra9455
@abhimanyumishra9455 9 жыл бұрын
You are simply genius..
@pranaysamrit8944
@pranaysamrit8944 7 жыл бұрын
Your videos are sooo awesome
@yunustaliperol6912
@yunustaliperol6912 4 жыл бұрын
Firstly, this is the best video ever on this topic for sure...But I have a question : Why the function ADD returning the "c" instead of "&c"??? It is returning "c" but we are writing the address of "c" in to the *ptr in the stack??? This confused me a bit...
@akshdeeprajawat9642
@akshdeeprajawat9642 5 жыл бұрын
Take a bow sir !!!!!!!
@crazytech3519
@crazytech3519 6 жыл бұрын
really great work sir...
@youyiliu7556
@youyiliu7556 6 жыл бұрын
Good, better, the best!
@manishthakur9797
@manishthakur9797 5 жыл бұрын
Great Explanation!
@ranjithks7
@ranjithks7 9 жыл бұрын
The PrintHelloWorld() function overwrittens the address of *c in Add() is aweful. Good to understand the behavior of Call Stack
@zekininadresi
@zekininadresi 6 жыл бұрын
IMO, this video is just amazing.
@someinteresting5629
@someinteresting5629 3 жыл бұрын
Very clear. Thank you
@cyborgdale
@cyborgdale 7 жыл бұрын
At 3:42 this is pass-by-pointer, NOT pass-by-reference. In pass-by-reference, you would call just as you would in pass-by-value but the parameter list would dereference the variables using the dereference operator '&'. The received reference variable is then an 'alias' and can be used syntactically just like a local variable without having to dereference. Changing this variable however would have scope OUTSIDE of the function and therefore change the corresponding variable in main(). The difference is that you can do "pointer arithmetic" on pointers (changing the address pointed to) but not on references.
@sarthakjoshi3797
@sarthakjoshi3797 7 жыл бұрын
In C language, passing by reference can only and only be accomplished using pointers. I think what you mean when you say pass-by-reference using "int& x" as parameter in a function is pass-by-reference in C++, which is a new concept in C++, not present in C. So this mycodeschool guy is kinda right:)
@cyborgdale
@cyborgdale 7 жыл бұрын
Sarthak Joshi Actually what I meant to say was "pass-by-address" instead of "pass-by-pointer". I keep it straight in my head by "thinking" of it as "pass-by-pointer", even though that term is not correct. It helps me remember to use the dereferencing operator in the function parameter list and to dereference the variable in the function body, whereas pass-by-reference automatically dereferences. I should have used the proper term so, thanks for calling me out on it.
@LimeriuxasLT
@LimeriuxasLT 2 жыл бұрын
excellent video, thanks!!!!!!
@rakshitks7850
@rakshitks7850 5 жыл бұрын
excellent playlist
@martingruscher7173
@martingruscher7173 11 жыл бұрын
Well explained, thanks a lot!
@guledalprashanth
@guledalprashanth 8 жыл бұрын
Just awesome dude, thanks!
Function Pointers in C / C++
11:57
mycodeschool
Рет қаралды 440 М.
Pointers as function arguments - call by reference
14:16
mycodeschool
Рет қаралды 490 М.
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.
UFC 287 : Перейра VS Адесанья 2
6:02
Setanta Sports UFC
Рет қаралды 486 М.
Memory leak in C/C++
17:55
mycodeschool
Рет қаралды 247 М.
you will never ask about pointers again after watching this video
8:03
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 679 М.
How to Write Function-Like Preprocessor Macros (C example)
13:59
Jacob Sorber
Рет қаралды 44 М.
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,5 МЛН
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 341 М.
Dynamic memory allocation in C - malloc calloc realloc free
17:35
mycodeschool
Рет қаралды 892 М.
Pointers in C / C++ [Full Course]
3:47:23
freeCodeCamp.org
Рет қаралды 4,9 МЛН