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

КОМЕНТАРІ • 348

  • @jaifer8
    @jaifer8 10 років тому +235

    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

    • @mycodeschool
      @mycodeschool  10 років тому +135

      Thanks Jai ! I do not have the heavy degrees to become a professor. :P

    • @johnathanpatrick3593
      @johnathanpatrick3593 7 років тому +16

      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.

    • @monikaparmar2061
      @monikaparmar2061 4 роки тому

      @@ajaykarthik4520 Unfortunately, the creator of mycodeschool passed away a few years ago. He was known by pseudonym "humblefool". You can search about him.

    • @ajaykarthik4520
      @ajaykarthik4520 4 роки тому

      @@monikaparmar2061 Oh so sad..... Thank you for replying

    • @utkarshaggarwal1631
      @utkarshaggarwal1631 4 роки тому

      @@mycodeschool hey, who taught this particular playlist, was it the programmer known as the "HUMBLEFOOL" who died?

  • @mycodeschool
    @mycodeschool  11 років тому +38

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

    • @sugamkumar8266
      @sugamkumar8266 4 роки тому +1

      If we add return a in increment fn then it should return 11 to main function?

    • @kensei4237
      @kensei4237 3 роки тому

      Sugam Kumar nope

    • @akhilgupta3664
      @akhilgupta3664 3 роки тому +2

      @@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 !!

    • @sugamkumar8266
      @sugamkumar8266 3 роки тому +1

      @@akhilgupta3664 👍👍

  • @sahil1053
    @sahil1053 3 роки тому +2

    Who needs code with Harry ... You are the best ❤️

  • @abuahchukwuedo6565
    @abuahchukwuedo6565 8 років тому +6

    Wow, literally had problems undersatnding pointers for like 8 months. Watching your videos on the topic really open my eyes. You deserve an award.

  • @atanatirosgiliat954
    @atanatirosgiliat954 10 років тому +33

    I could not have asked for a better explanation, thank you.

  • @jwj410
    @jwj410 7 років тому +32

    Literally blown my mind with some things I've been struggling to understand for a couple of years now...thank you so much!

  • @leixun
    @leixun 4 роки тому +16

    *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

  • @Donotmicrowavee
    @Donotmicrowavee 4 роки тому +5

    the amount of new things i learn from you instead of my school. i wish my school tuition goes to you

  • @gultekinbutun7910
    @gultekinbutun7910 2 роки тому +8

    A perfect explanation to pointers and how to use. Even the video is 8 years old it still teaches valuable information, well done.

  • @bayram00
    @bayram00 3 роки тому +3

    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.

  • @CherryMarz
    @CherryMarz 6 років тому +1

    you just explained functions, pointers, variables and the stack so clearly and visually in one video. extremely helpful - i could not thank you enough!

  • @kevinjohansson3923
    @kevinjohansson3923 9 років тому +219

    I'm Albert ;(.
    Or rather, I was until I saw your videos :D.

  • @mukundmadhusudanatre4368
    @mukundmadhusudanatre4368 6 років тому

    The best video on pointers and call by reference, you employed well enough approaches to make it incredibly easy to understand. Take a bow!

  • @akshathakini157
    @akshathakini157 7 років тому

    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!

  • @user-uu5xd7mb8i
    @user-uu5xd7mb8i Рік тому

    Even the recent big UA-camrs cant match your teaching style. You are the best professor! Thank you so much :)

  • @stardust857
    @stardust857 Рік тому +2

    9 years old video, still relevant to this day, thanks for making the concept of pointers crystal clear, god bless u, good man!

  • @aw7628
    @aw7628 8 років тому +2

    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!

  • @mycodeschool
    @mycodeschool  11 років тому +1

    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.

  • @masterchef8671
    @masterchef8671 8 років тому

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

  • @shreedharhegde7906
    @shreedharhegde7906 5 років тому

    Best explanation of pointers on UA-cam so far. Thanks a lot.

  • @PremSai14
    @PremSai14 5 років тому

    This is one of the most simplest and clearest explanation i have ever seen on the pointers in all of history. Very impressive 😃😃

  • @debosmitadas1488
    @debosmitadas1488 6 років тому +1

    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

  • @arnabsadhukhan
    @arnabsadhukhan Рік тому

    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.

  • @diahidvegi8536
    @diahidvegi8536 2 місяці тому

    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.

  • @Backstabbio
    @Backstabbio 10 років тому

    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!

  • @katiemartinez772
    @katiemartinez772 Рік тому

    I cannot explain how much I love you. Thank you so much! Your explanations are the best.

  • @supreethuilgol1967
    @supreethuilgol1967 7 років тому +2

    best series of explanation on pointers ever on this earth!!

  • @cookiesandcode2860
    @cookiesandcode2860 7 років тому

    The subtitles are incredibly helpful. They make your videos even better! Thanks :)

  • @georgenabil2348
    @georgenabil2348 5 років тому +8

    two years of coding and its the first time to understand this part
    beautiful work can you make a series on oop

  • @gucluceyhan
    @gucluceyhan 8 років тому

    It is so sad and so unfortunate that I found your lessons yesterday.
    They are pure jewel. Thank you...

  • @418aditya3
    @418aditya3 4 роки тому +1

    The way you are explaining is absolutely brilliant. Even our professors won't even know the names of what you are telling..🙏🙏

  • @thekrazystuff5807
    @thekrazystuff5807 3 роки тому

    This is the first time I understood what exactly call by reference is .... thank you so much.
    Subscribed You

  • @smashueatu
    @smashueatu 9 років тому +2

    Wow. Incredible. I know you don't need any more praise, but this is amazing! Thank you.

  • @ShivamKendre-fc3su
    @ShivamKendre-fc3su 4 роки тому

    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.

  • @HrishikeshMahajan007
    @HrishikeshMahajan007 4 роки тому +1

    Shame on the 52 people who disliked. Such great content and explanation deserves credit. Good work Animesh.

  • @coin5207
    @coin5207 3 роки тому +1

    Your precise explanations are putting collage professors to shame! Kudos to you

  • @aburridohp
    @aburridohp 9 років тому +25

    You rock!!! The expression after watching this tutorial will be:
    " Right in the money baby"
    Thanks for the perfect explanation.

  • @mdabusayeed2305
    @mdabusayeed2305 7 років тому

    Tough topics get easy: One of the best video lecture series I ever had

  • @adityamali1862
    @adityamali1862 5 років тому

    You are the best teacher ive ever met...

  • @ajinkyakirkire6561
    @ajinkyakirkire6561 4 роки тому +2

    That's the best I've ever understood call by reference in 4 years of learning c++

  • @ermx8
    @ermx8 8 років тому +24

    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.

    • @rohanpatil8417
      @rohanpatil8417 6 років тому +15

      He Studied at Indian Institute of Information Technology!

  • @samdavepollard
    @samdavepollard 3 роки тому

    I have several books on C, including those that are top rated on amazon.
    These videos beat them all.
    Exceptionally useful. Thank You.

  • @BhargabKakati
    @BhargabKakati 7 років тому +1

    Trying to transform from an Albert to a programmer.Thank you so much.cleared the concept

  • @thisaintmyrealname1
    @thisaintmyrealname1 7 років тому +1

    Excellent Teacher. I totally admire you. Thanks for this amazing material!

  • @CodeRCreatives
    @CodeRCreatives 3 роки тому

    the best channel on UA-cam for learning

  • @sriramhariharan8448
    @sriramhariharan8448 9 місяців тому

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

  • @urdev65
    @urdev65 7 років тому +1

    i finally understand why indians are so good at programming, because their teachers teaching skills are far more better than our's.

  • @ranavivek819
    @ranavivek819 9 років тому +1

    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

  • @omerpalabiyik
    @omerpalabiyik 2 роки тому

    I don't really comment that much, but this is pure perfection!!! RIP Harsha

  • @DaveJLin
    @DaveJLin 6 років тому +25

    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!

    • @marcelalves6196
      @marcelalves6196 5 років тому +8

      @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)

    • @shreyashchauhan8567
      @shreyashchauhan8567 5 років тому +1

      Can you elaborate more please

    • @monikaparmar2061
      @monikaparmar2061 4 роки тому

      @@marcelalves6196 Thanks very much. This is really helpful.

  • @ahmadfaiq85
    @ahmadfaiq85 4 роки тому

    Very clear and extensive explanation. Thank you for your work.

  • @micado88
    @micado88 11 років тому

    The best call by reference explanation indeed ... the memory showing method is very helpful
    thanks!

  • @henokweldemicael
    @henokweldemicael 9 років тому

    You sir are AWESOME! Why cannot my professors explain it like this? They just over-complicate it took sophisticated!

  • @leonperianu7684
    @leonperianu7684 5 років тому

    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:)

  • @rhythmsharma4561
    @rhythmsharma4561 6 років тому

    Thanks to you, now i understand concept of pointer, call by reference and call by value

  • @stickydamper
    @stickydamper 4 роки тому +18

    Rest in peace brother, your legacy lives after you :-(

    • @rickyruan6230
      @rickyruan6230 2 роки тому +1

      I am sry, may I know what's going on with this great professor?

    • @ighsight
      @ighsight 2 роки тому +5

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

    • @efurudesigns
      @efurudesigns Рік тому +2

      Omg! my heart breaks! , God! Rest in peace such a great teacher 😢❤

  • @upmabaranwal5672
    @upmabaranwal5672 7 років тому

    very very helpful and ur explanation method is unbelivable

  • @Priyanka-rl7hk
    @Priyanka-rl7hk 7 років тому

    you are really great.... thank you very much....the way you explain is really awesome....faculties from renowned institute should learn from you

  • @HarmanChahal09
    @HarmanChahal09 7 років тому +1

    @mycodeschool which ide or compiler of which version you are using bro please give complete details . thanks in advance you are the best .

  • @mrkalykuuber
    @mrkalykuuber 8 років тому +15

    this how the great teacher is ,, thanks alot

  • @aungthiha9443
    @aungthiha9443 3 роки тому

    Thanks sir .
    You are the best teacher in the world.

  • @ayush7805
    @ayush7805 7 років тому +16

    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

    • @Opacity5
      @Opacity5 6 років тому

      i didn't get the reference behind Albert? whats that mate?

  • @TheFlyguy31
    @TheFlyguy31 9 років тому

    Thank you...i have written it as you explained it..Great lesson!

  • @rahul930
    @rahul930 7 років тому

    This is best...I think, even paid tutorials are not as good as this......Thanks a lot man....:)

  • @inclinedscorpio
    @inclinedscorpio 5 років тому +5

    *Most of us were unclear of the fact what we actually want which was cleared after watching your MASTERPIECE.*

  • @ananyapassi4683
    @ananyapassi4683 5 років тому +1

    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.

  • @narendra564
    @narendra564 6 років тому

    This is the best explanation I got, Thank you.

  • @vikaspatel3994
    @vikaspatel3994 9 років тому +1

    Amazing Explaination..............like a c in sea...............Thanks a lot.........fan of u

  • @kristinashiryaginasalini1626
    @kristinashiryaginasalini1626 8 років тому

    Thank u very much ! With ur video it's easy to understand difficult things!

  • @AshutoshKumar-mv5um
    @AshutoshKumar-mv5um 6 років тому

    Bhaiiiiiiiii great piece of knowledge

  • @lindsey5236
    @lindsey5236 5 років тому

    You are awesome man !!! best tutorial of pointer ever , thank you so much for making it !!

  • @lighttangerinesky
    @lighttangerinesky 9 років тому +1

    These are very helpful! Thank you so much!

  • @abhishekpai
    @abhishekpai 5 років тому

    Superb video!!! Loved it. Beautifully explained👍👍

  • @nipundhananjaya1367
    @nipundhananjaya1367 7 років тому

    oh,,,, thank you very much ! very clear explanation. the best explanation i have ever seen ... good luck and keep up!

  • @nayangupta5277
    @nayangupta5277 3 роки тому +1

    bhai bahut achaa kaam karte ho aap. thank you so much .

  • @IamSevuras
    @IamSevuras 7 років тому

    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

  • @srivathsar4434
    @srivathsar4434 7 років тому

    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?

  • @greegeo
    @greegeo 3 роки тому

    THANK YOU! exactly what I was looking for

  • @damoimyers2651
    @damoimyers2651 4 роки тому

    At least someone can explain it so I can understand.... Thanks bro!

  • @JohnnyFive
    @JohnnyFive 10 років тому

    Thank you so much. You did a wonderful job explaining this.

  • @ravaicakacaka7295
    @ravaicakacaka7295 6 років тому

    youre better than our professor....who also works at google...
    thanks !!!

  • @adityaprakash7355
    @adityaprakash7355 8 років тому

    bro im doing pg dac course through cdac chennai and i find your lectures very usefull

  • @mohanaddarwish2307
    @mohanaddarwish2307 8 років тому +4

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

  • @pathruduchintakayala4513
    @pathruduchintakayala4513 7 років тому

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

  • @wormoSTEEZE
    @wormoSTEEZE 7 років тому

    thank you, very informative and helped me understand a lot of important things.

  • @reubenfernandes5263
    @reubenfernandes5263 10 років тому

    m preparing for my exams.....that was a lots of help.....thanks

  • @akashagarwal7529
    @akashagarwal7529 6 років тому

    Very good example to teach call by reference use. thanks

  • @radiator007
    @radiator007 8 років тому

    Awesome explanation to a difficult topic.. Thank you sir.

  • @shivamrai4052
    @shivamrai4052 4 роки тому

    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 ?

  • @vijayank3207
    @vijayank3207 9 років тому +1

    very clear explanation sir..thank you soo much

  • @soumitghosh4077
    @soumitghosh4077 10 років тому +1

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

  • @IndianDesiTennis
    @IndianDesiTennis 3 роки тому

    After 3 years working as a CS professional, I have finally understood call by value and call by reference lol

  • @ramyak953
    @ramyak953 6 років тому

    thanks for this beautiful video , I m going into deep day by day!!!!

  • @kailashkolluru2398
    @kailashkolluru2398 7 років тому

    does the data type of function varies the allocation of memory to the function in stack

  • @soumyajitnayak970
    @soumyajitnayak970 10 років тому

    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

  • @rupeshpredator6855
    @rupeshpredator6855 5 років тому

    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

  • @mycodeschool
    @mycodeschool  11 років тому +4

    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.

  • @melihaslan9509
    @melihaslan9509 4 роки тому

    Amazing explanation!!

  • @ramkumarrammohan3745
    @ramkumarrammohan3745 7 років тому

    Very awesome explanations. Thank you.

  • @rearea784
    @rearea784 7 років тому +4

    I like Albert's adventures in programming :)