Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. what are the differences between pass-by-value and pass-by-reference in C++

what are the differences between pass-by-value and pass-by-reference in C++

Scheduled Pinned Locked Moved Graphics
5 Posts 5 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ortegacarey
    wrote on last edited by
    #1

    Hi all, can you tell me what are the differences between pass-by-value and pass-by-reference in C++? thankyou

    V 1 Reply Last reply
    0
    • O ortegacarey

      Hi all, can you tell me what are the differences between pass-by-value and pass-by-reference in C++? thankyou

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Didn't Google help you with this problem?:confused: [the differences between pass-by-value and pass-by-reference in C++ - Google Search](https://www.google.com/search?q=the+differences+between+pass-by-value+and+pass-by-reference+in+C%2B%2B&sourceid=chrome&ie=UTF-8)

      T 1 Reply Last reply
      0
      • V Victor Nijegorodov

        Didn't Google help you with this problem?:confused: [the differences between pass-by-value and pass-by-reference in C++ - Google Search](https://www.google.com/search?q=the+differences+between+pass-by-value+and+pass-by-reference+in+C%2B%2B&sourceid=chrome&ie=UTF-8)

        T Offline
        T Offline
        tronderen
        wrote on last edited by
        #3

        Pass-by-value is when someone presents an answer to your problem. Pass-by-reference is when someone tells you "Why don't you just f***g google it?" For being slightly more helpful: Pass-by-value is when the caller makes a copy of the argument and hands this copy over to you. It carries no information about where your copy of the value is taken from - it may very well be the value of an expression directly stated in the argument list of the actual call. The copy is yours, and whatever you do to it won't affect anyone else. The value (copy) exists only as long as your method is running. Pass-by-reference is when the caller doesn't give you a copy of the value, but rather tells you where you can find it, i.e. the location (address) in memory where the value is stored. You have to go and look there to find the value. In most cases, other parts of the program will be looking in the same location, and if your method changes the value stored, others who subsequently look there, will see your modifications to the value. The location exists both before and after the call to your method. There is nothing C++ specific to this; it goes for all languages (or rather: all languages providing both call-by-value and call-by-reference - which are most of them).

        L E 2 Replies Last reply
        0
        • T tronderen

          Pass-by-value is when someone presents an answer to your problem. Pass-by-reference is when someone tells you "Why don't you just f***g google it?" For being slightly more helpful: Pass-by-value is when the caller makes a copy of the argument and hands this copy over to you. It carries no information about where your copy of the value is taken from - it may very well be the value of an expression directly stated in the argument list of the actual call. The copy is yours, and whatever you do to it won't affect anyone else. The value (copy) exists only as long as your method is running. Pass-by-reference is when the caller doesn't give you a copy of the value, but rather tells you where you can find it, i.e. the location (address) in memory where the value is stored. You have to go and look there to find the value. In most cases, other parts of the program will be looking in the same location, and if your method changes the value stored, others who subsequently look there, will see your modifications to the value. The location exists both before and after the call to your method. There is nothing C++ specific to this; it goes for all languages (or rather: all languages providing both call-by-value and call-by-reference - which are most of them).

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Victor gave "value" AND a "reference". Should he read it out loud or copy and paste it?

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          1 Reply Last reply
          0
          • T tronderen

            Pass-by-value is when someone presents an answer to your problem. Pass-by-reference is when someone tells you "Why don't you just f***g google it?" For being slightly more helpful: Pass-by-value is when the caller makes a copy of the argument and hands this copy over to you. It carries no information about where your copy of the value is taken from - it may very well be the value of an expression directly stated in the argument list of the actual call. The copy is yours, and whatever you do to it won't affect anyone else. The value (copy) exists only as long as your method is running. Pass-by-reference is when the caller doesn't give you a copy of the value, but rather tells you where you can find it, i.e. the location (address) in memory where the value is stored. You have to go and look there to find the value. In most cases, other parts of the program will be looking in the same location, and if your method changes the value stored, others who subsequently look there, will see your modifications to the value. The location exists both before and after the call to your method. There is nothing C++ specific to this; it goes for all languages (or rather: all languages providing both call-by-value and call-by-reference - which are most of them).

            E Offline
            E Offline
            Edward Jacksan
            wrote on last edited by
            #5

            Thanks for breaking down the concepts of pass-by-value and pass-by-reference in such an engaging way! Your explanation makes it clear how these methods work and their implications in programming. It's great to see how this applies across various languages, not just C++. For those interested in enhancing their programming skills, it's essential to grasp these differences.

            https://www.redspider.ae/.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups