Pointers as function arguments - call by reference
Вставка
- Опубліковано 15 лют 2013
- See complete series on pointers here • Pointers in C/C++
In this lesson, we will see one of the use cases of pointer variables which is using them as argument to functions. We will describe the concept of call by value and call by reference.
Please see previous lessons here-
• Pointers in C/C++
For practice problems and more, visit: www.mycodeschool.com
Like us on Facebook: / mycodeschool
Follow us on twitter: / mycodeschool
How are you not a professor? Your better at explaining things than some of the more pronounced professors at my school. Thank you very much, this is helping me prepare for CS1
Thanks Jai ! I do not have the heavy degrees to become a professor. :P
He is the best that I've seen yet. Using Feynman learning techniques combined with the videos presented makes learning enjoyable. One can see how rote memorization fails to develop comprehension for abstract concepts.
@@ajaykarthik4520 Unfortunately, the creator of mycodeschool passed away a few years ago. He was known by pseudonym "humblefool". You can search about him.
@@monikaparmar2061 Oh so sad..... Thank you for replying
@@mycodeschool hey, who taught this particular playlist, was it the programmer known as the "HUMBLEFOOL" who died?
These four sections are created for each program. It will not be safe for programs to enter each other's memory. So, OS allocates memory for each application. The size of stack, text/code segment and global section is decided at compile time. Heap can grow during run time.
P.S: There are no stupid questions, there are only stupid answers. So, it's me who may be wrong. :)
If we add return a in increment fn then it should return 11 to main function?
Sugam Kumar nope
@@sugamkumar8266 Yes, also you have to change the increment return type function from void to int , and in main function you have to catch the returned a value from incremental function. Thats also work !!
@@akhilgupta3664 👍👍
Who needs code with Harry ... You are the best ❤️
Wow, literally had problems undersatnding pointers for like 8 months. Watching your videos on the topic really open my eyes. You deserve an award.
I could not have asked for a better explanation, thank you.
Literally blown my mind with some things I've been struggling to understand for a couple of years now...thank you so much!
*My takeaways:*
1. Memory: heap, stack, static/global and code 4:21
2. *a* in the *Incremental* function is deleted before the program calling *printf* 8:20
3. Call by value 10:10
4. Call by pointer/reference 11:09
the amount of new things i learn from you instead of my school. i wish my school tuition goes to you
A perfect explanation to pointers and how to use. Even the video is 8 years old it still teaches valuable information, well done.
I'm watching the whole pointer playlist and I must say that these are the best I could find on the whole internet...
We are simultaneously learning about assembly (or low level stuff) which is awesome! Everything makes sense now and as I watch more videos, the clarification increases.
you just explained functions, pointers, variables and the stack so clearly and visually in one video. extremely helpful - i could not thank you enough!
I'm Albert ;(.
Or rather, I was until I saw your videos :D.
dISGUSTING!
Isaac Fujimoto ??
The best video on pointers and call by reference, you employed well enough approaches to make it incredibly easy to understand. Take a bow!
I am reiterating all the compliments you received from others before me! You make a fantastic teacher!! Totally love your explanation! They make for a crystal clear understanding of these concepts which are otherwise very confusing! A big thank you!
Even the recent big UA-camrs cant match your teaching style. You are the best professor! Thank you so much :)
9 years old video, still relevant to this day, thanks for making the concept of pointers crystal clear, god bless u, good man!
You have solved what I have been confused with over the years, thanks for your contribution and efforts on great teaching! You are the best lecturer I have met so far and you should become a professional professor!
Do you mean, we should put the tutorial number? Please see the description for complete playlist on pointers. We are still adding tutorials in this playlist.
this is the most useful 10 mins that I've spent in trying to understand pointers !! such an in depth explanation .. Always wonder why my college teachers DON'T teach like u ppl ..Think i have to recommend these to them first..Thank you so much for sharing ur knowledge !! U R AWSM !!
Best explanation of pointers on UA-cam so far. Thanks a lot.
This is one of the most simplest and clearest explanation i have ever seen on the pointers in all of history. Very impressive 😃😃
For the first time I am loving pointers!! Thank u soo much.. you have taught me what the books , teachers and trainers could never teach me
I went through a lot of youtube video lectures but finally found your playlist, and it's the best of all, your teaching skills are amazing, really appreciate your efforts.
I cannot thank you enough, this cleared up so many days of confusion.. Really appreciate the effort you've put into these videos. Very valuable.
Thank you for taking the time to make these. I admit that at first I had a little trouble with your accent, but I've gotten used to it now. The information is great! Thanks!
I cannot explain how much I love you. Thank you so much! Your explanations are the best.
best series of explanation on pointers ever on this earth!!
The subtitles are incredibly helpful. They make your videos even better! Thanks :)
two years of coding and its the first time to understand this part
beautiful work can you make a series on oop
It is so sad and so unfortunate that I found your lessons yesterday.
They are pure jewel. Thank you...
The way you are explaining is absolutely brilliant. Even our professors won't even know the names of what you are telling..🙏🙏
This is the first time I understood what exactly call by reference is .... thank you so much.
Subscribed You
Wow. Incredible. I know you don't need any more praise, but this is amazing! Thank you.
I learned about pointers from this channel a year ago and i haven't revised still I didn't forgot anything these are really great videos which gives clear image of everything. thank you animesh sir I am waiting for your videos on algorithms as well and ya we miss you harsha sir.
Shame on the 52 people who disliked. Such great content and explanation deserves credit. Good work Animesh.
Your precise explanations are putting collage professors to shame! Kudos to you
You rock!!! The expression after watching this tutorial will be:
" Right in the money baby"
Thanks for the perfect explanation.
aburridohp Thanks :)
Tough topics get easy: One of the best video lecture series I ever had
You are the best teacher ive ever met...
That's the best I've ever understood call by reference in 4 years of learning c++
Oooh man!!! Are U a Standfor's or MIT's or Harvard's Proffesor??? Your teching method is excellent, you explain very clear. I was crashing my brain trying to understand real uses for pointers and how they work in memory's computers. I got all of this pointers stuff clear right now thanks to you man. greetings from Mexico.
He Studied at Indian Institute of Information Technology!
I have several books on C, including those that are top rated on amazon.
These videos beat them all.
Exceptionally useful. Thank You.
Trying to transform from an Albert to a programmer.Thank you so much.cleared the concept
Excellent Teacher. I totally admire you. Thanks for this amazing material!
the best channel on UA-cam for learning
I have never seen someone explain the concept of call by reference and value through stack(which is how it works in real life). kudos!!
i finally understand why indians are so good at programming, because their teachers teaching skills are far more better than our's.
sir, u are simply amazing....great explaination,,,brilliant simplification of concepts using examples,,,great quality video and audio,,,mostly to the point ,,,keep up the gud work,,,U ROK
I don't really comment that much, but this is pure perfection!!! RIP Harsha
Minor correction: your example is strictly speaking "call by pointer", not "call by reference." Call by reference would have the signature: "void increment(int &a)" and would be called using "increment(a);". Otherwise, great explanation - hope you continue sharing your teaching talent. I really appreciate your videos!
@Mekonen S He's partially wrong. His example didn't work because that is C++, not C.
Nevertheless, he was correct when he said that the example in the video is not passing by reference. Strictly speaking, that is also pass-by-value - it's just that you're passing the pointer by value.
C doesn't pass by reference, only by value. I know this can be really confusing, and newer definitions of pass-by-reference and pass-by-value complicated things a little bit, so I recommend reading the following:
- stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value
- stackoverflow.com/questions/2229498/passing-by-reference-in-c
- www.quora.com/What-are-the-advantages-of-using-references-over-pointers (see Sergey's answer)
Can you elaborate more please
@@marcelalves6196 Thanks very much. This is really helpful.
Very clear and extensive explanation. Thank you for your work.
The best call by reference explanation indeed ... the memory showing method is very helpful
thanks!
You sir are AWESOME! Why cannot my professors explain it like this? They just over-complicate it took sophisticated!
you are better than 4 of my teacher "stacked" together (got the little joke i put here?) . Great job man, keep the good work, You are like me, you explain it Simple and logial, step by step. Your videos till this, about one hour, explained better than my teachers tried in 10 hours.... Pretty awesome, i guess:)
Thanks to you, now i understand concept of pointer, call by reference and call by value
Rest in peace brother, your legacy lives after you :-(
I am sry, may I know what's going on with this great professor?
@@rickyruan6230 From what I can gather he died after being struck by a car. I am not sure how long ago but I think it has been maybe 4 or so years. Tributes to this great teacher are all over the comments. Watching these videos for me is bittersweet, I would love to personally thank him for how he has helped my computer science understanding grow.
Omg! my heart breaks! , God! Rest in peace such a great teacher 😢❤
very very helpful and ur explanation method is unbelivable
you are really great.... thank you very much....the way you explain is really awesome....faculties from renowned institute should learn from you
@mycodeschool which ide or compiler of which version you are using bro please give complete details . thanks in advance you are the best .
this how the great teacher is ,, thanks alot
Thanks sir .
You are the best teacher in the world.
5 alberts disliked ..
however , you rock by these videos , great explanation , and the most importan thing is that you explain such deep toics soo easily , thumbs up for the efforts
i didn't get the reference behind Albert? whats that mate?
Thank you...i have written it as you explained it..Great lesson!
This is best...I think, even paid tutorials are not as good as this......Thanks a lot man....:)
*Most of us were unclear of the fact what we actually want which was cleared after watching your MASTERPIECE.*
great video! I was wondering however that if instead of void increment the function would have been int increment and at the end would have returned a ...would there still be an issue....by using this method we can get the desired result without the use of pointers. Please correct me if I am wrong.
This is the best explanation I got, Thank you.
Amazing Explaination..............like a c in sea...............Thanks a lot.........fan of u
Thank u very much ! With ur video it's easy to understand difficult things!
Bhaiiiiiiiii great piece of knowledge
You are awesome man !!! best tutorial of pointer ever , thank you so much for making it !!
These are very helpful! Thank you so much!
Superb video!!! Loved it. Beautifully explained👍👍
oh,,,, thank you very much ! very clear explanation. the best explanation i have ever seen ... good luck and keep up!
bhai bahut achaa kaam karte ho aap. thank you so much .
Hey bro,
Just wondering if there was any particular reason you wrote the *p in parenthesis on the right hand side of the '=' operator in the increment function? I tried the code without and it works fine
Doesn't the stack grow downwards (on most architectures) in the representation shown at 14:15 .
So, the main() or stack frame would be at memory 600 and any call stack below it. Am I correct?
THANK YOU! exactly what I was looking for
At least someone can explain it so I can understand.... Thanks bro!
Thank you so much. You did a wonderful job explaining this.
youre better than our professor....who also works at google...
thanks !!!
bro im doing pg dac course through cdac chennai and i find your lectures very usefull
DUDE, GREAT JOb! omg i regret not watching this video 3 years ago when i was in college..... despite the fact it was created in 2013 but still >.
+mycodeschool Awesome Tutorial and Explanation. But please take care of Audio output(good if its bit louder) if it was rectified this will be the best tutorial. Thanks man....
thank you, very informative and helped me understand a lot of important things.
m preparing for my exams.....that was a lots of help.....thanks
Very good example to teach call by reference use. thanks
Awesome explanation to a difficult topic.. Thank you sir.
I have a doubt.
If we will use return in increment function and change the type from void to int then we can also get the changed value of a ?
very clear explanation sir..thank you soo much
@mycodeschool but sir when we use 'return a' from increment and change function void to int then value is 11,,so sir can u tell me what terminology happened then?
After 3 years working as a CS professional, I have finally understood call by value and call by reference lol
thanks for this beautiful video , I m going into deep day by day!!!!
does the data type of function varies the allocation of memory to the function in stack
seriously ur the best teacher in whole youtube ,i totally agree wid u #Amandeep i hv no words ,i think even u dnt konw how good u r ,plz keep going on nd frankly speaking dis this d best school or clg i hv ever seen
In the final program why are we using increment(&a) and not incremental (a)? If we use incremental (&a) it will increment the address located to the byte right ? Can anyone explain
Hi Gaukhar,
Virtual address space in a typical architecture should probably be represented like what you are saying. The intent here was to show that there are these logical segments in applications memory with specific roles. How they are implemented is a thing of architecture and can vary with machine, OS and compiler. For example, whether stack will grow from low address to high or high to low will also depend upon architecture.
Amazing explanation!!
Very awesome explanations. Thank you.
I like Albert's adventures in programming :)