C++ Programming Tutorial 67 - Pass By Reference and Pass By Value

Поділитися
Вставка
  • Опубліковано 14 жов 2024
  • Start your software dev career - calcur.tech/de... 💯 FREE Courses (100+ hours) - calcur.tech/al...
    🐍 Python Course - calcur.tech/py...
    ✅ Data Structures & Algorithms - calcur.tech/ds...
    ~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~
    ✉️ Newsletter - calcur.tech/ne...
    📸 Instagram - / calebcurry
    🐦 Twitter - / calebcurry
    🔗 LinkedIn - / calebcurry
    ▶️ Subscribe - calcur.tech/sub...
    👨🏻‍🎓 Courses - www.codebreakt...
    ~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~
    ↪ My Amazon Store - www.amazon.com...
    🅿 Patreon - calcur.tech/pat...
    🅖 GitHub Sponsors - github.com/spo...
    Ⓟ Paypal - paypal.me/calcur
    🅑 Bitcoin - 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
    🅔 Eth - 0x350139af84b60d075a3a0379716040b63f6D3853
    📈 Buy Bitcoin - calcur.tech/cr...
    Reserve the Ruby Steel crypto rewards card and get a $25 bonus (use affiliate code "Caleb") - calcur.tech/cr...

КОМЕНТАРІ • 77

  • @javathehut3593
    @javathehut3593 3 роки тому +40

    The concept is simple but when you actually have to do it its difficult

  • @Awesimile
    @Awesimile 3 роки тому +42

    As a computer science student, I really appreciate all of your videos. They make all these complicated topics so much clearer. :)

  • @vortex_7574
    @vortex_7574 4 роки тому +162

    On behalf of all programming students;
    cout

    • @khaledAli03
      @khaledAli03 4 роки тому +22

      std::cout

    • @jacoblehrer4198
      @jacoblehrer4198 4 роки тому +4

      @@khaledAli03 they could've specified "using namespace std;" otherwise you needed to let them know they're missing a whole lot of other stuff lol

    • @jesusgarciagutierrez7301
      @jesusgarciagutierrez7301 4 роки тому +27

      @@khaledAli03
      #include
      using namespace std;
      int main(){
      cout

    • @minsungkim6792
      @minsungkim6792 3 роки тому +18

      nerds

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

      "THANK YOU!!!
      "

  • @Inglonias
    @Inglonias 2 роки тому +13

    One thing I have learned is that it is good practice to pass things by reference unless you have a good reason not to, because if you pass by value, the computer also needs to copy the object whenever a function gets called. If the object used is especially large, or you're calling a function especially often, or both, passing by reference means your code will run much faster.

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

      I was wondering this same thing while watching the video. I'm unsure if this is true, but as of now I don't have a reason to not agree with you. If anyone has some information we are both missing out on, please let us know

    • @67hutch
      @67hutch 8 місяців тому

      That's very true. I think that the same logic can also be applied to range-based for loops, by making the type of the declaration (the thing that comes before the ':' in the brackets) either auto& or const auto& (for if you want to be able to modify the element in the loop, or if the elements will not be modified in the loop, respectively. I hope that makes sense.

    • @ipodtouch470
      @ipodtouch470 8 місяців тому

      It depends what the function is doing but I prefer to use pass by value when possible. I don’t like the idea of being able to mutate a variable that isn’t defined in the scope of the function. Obviously though there are times when you can’t prevent this like when you mutate an object inside a cpp function

  • @abugslife2461
    @abugslife2461 4 роки тому +12

    thank you so much!! i've been stuck on this concept for so long, but it's starting to make sense! thank you!!!

  • @ChrisSoCLD
    @ChrisSoCLD 4 роки тому +13

    I needed this. I almost have a minor in CS and didn't clearly understand this concept until now. THANK YOU!

  • @axelman8547
    @axelman8547 Рік тому +1

    Dude! Yes finally I understand why my value changes, but when the funtion is ended, the value is restored. The &value did the trick, man I lost 6 hours of trial and error and this dit it in 10 seconds. Thank you for your knowledge . Cheers

  • @Chad-cq6uy
    @Chad-cq6uy 3 роки тому +6

    Actually thank you so much, I've been stuck on functions for a week and a half now using codecademy, and I knew I was stuck on one concept, but could never figure it out. After this video I have so much of a better understanding. I never even knew the difference of passing by a reference to passing by value. Honestly this one of the best video I've come across on the internet in terms of explanation for beginners.

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

    you're damn underrated, pal. Thanks for easing down this important feature of C++

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

    I feel so validated that you acknowledged that there is a learning curve to writing an and sign. I’ve been working on my and sign lately too.

    • @ethanboba5262
      @ethanboba5262 Рік тому +1

      not to brag or anything but I did it rn first try

  • @rahileshanbi5551
    @rahileshanbi5551 4 місяці тому

    Thank you as an engineering student that has nothing to do with programming whatsoever but required to by my college. You've really helped me 😂

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

    He is a keeper of the peace, 'his name is...' We thank this man...

  • @РусланКаписъски

    Dazzling explanation! Greetings from Bulgaria!

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

    Really appreciate your efforts and make concepts very SIMPLE.
    Very few tutors/teachers can have this abilities.
    You helping many lives who struggle with C++.
    God bless you @Caleb

  • @universalalgorithm3263
    @universalalgorithm3263 4 роки тому +3

    OMG ty I watched this before a final and aced that portion of it.

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

    Once again, you nailed it with the explanation. Good job 👌

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

    Dude, I freaking love you. Thanks for your channel !!!

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

    Thank you for the explanation! I understood in 5 minutes the pass by concept!

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

      There are so many helpful youtubers that help me understamd within 5 minutes. I know the feel. Our professor tells us "You need to learn how to do 'X' concept" everytime you ask her something.... Like isn't it her job to teach me 'X' concept?

  • @Rex-ml5op
    @Rex-ml5op 3 роки тому +1

    Really like your explanation, very easy to understand. Job well done

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

    Should also mention that if you use a prototype, it also needs to have the & sign.

  • @GeoffryGifari
    @GeoffryGifari Рік тому +1

    what if our functions' argument is an array and the function modifies said array? can we do it if the type information is lost while passing the array as pointer?

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

    You're awesome and appreciated! Thanks for the content!

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

    you are a master of codifying these concepts into a easy to digest format, Codified by Caleb haha keep it up!!

  • @eenayeah
    @eenayeah 11 місяців тому

    This is definitely one of the more confusing things... Thank you for this explanation!

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

    i play your videos on 2x, you are not boring or slow, your explanations are so that even a dummer like me can understand it very easily even on high speed

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

    thank you so much that makes sense a lot

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

    can you do video on pointer variables and how pointer calculation works like integer ones outside int main. Mixing with array would be nice. I also want video of the pointer of single link to double link head to tail

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

    Really loved your explanation. Thank you!

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

    Thank you very much, this was so helpful

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

    Thanks a bunch for this!!!

  • @n-o-i-d
    @n-o-i-d 4 роки тому +1

    excellent explanation

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

    Thanks a lot, Sir.
    From India

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

    You know what else has skyrocketed since you started making this tutorial? The number of people who learned about a product that can help them deploy high-performance native apps on windows, android, iOS, macOS, and linux. Unfortunately I can't quite recall the name of it at the moment. Hopefully I'll hear it again soon, maybe even in the next video...

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

    Great explanation.

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

    I started to write a similar code as of the 4:58 time stamp. And canonically, I started with x = 5 and I was surprised to see you do the same...
    5:20 That's awesome!!! congrats, sir...
    BTW, Thank you very much for all your help so far...

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

    great explanation Thanks

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

    wow i needed this thank you

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

    in this case of using reference as parameter, why not just pass "int *" type instead? does the same thing.

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

    Brilliant!

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

    Thank you!

  • @МарияБородай-щ7з
    @МарияБородай-щ7з 16 днів тому

    Brilliant guy

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

    I couldn't get the Embarcadero to work. It wouldn't accept any serial number I was given. Thank you for the information

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

    Thanks so much.

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

    OMG, I love you! Thank you very much, Curry!

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

    Amazing!!

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

    Thank you sm!!!!

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

    wow, only 20K people actually wnat to improve software performance

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

    Crisp clear

  • @GOODBOY-vt1cf
    @GOODBOY-vt1cf 2 роки тому

    5:00

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

    I wish every tutorial about reference values wouldn't rely on arrays to explain it. Reference values come before arrays in my introductory CS class. One thing I don't really understand is enough, don't need two.

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

    Your curly brackets bro 💀

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

    very freat explaination

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

    Function header shouldn't be void do_stuff(int *x)? I admire your & drawing skills but mistake like that is unaccaptable for me in a tutorial video.

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

    i love you

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

    My “and”s look like a 4 on its side.

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

    Another one.

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

    the only reason i am not subscribing to your channel is the ad duration is way too annoying !

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

    I don't understand fml