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. Other Discussions
  3. The Weird and The Wonderful
  4. Pass by value and pass by reference

Pass by value and pass by reference

Scheduled Pinned Locked Moved The Weird and The Wonderful
24 Posts 15 Posters 0 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.
  • P Pete OHanlon

    It's passed by the lower intestinal tract.

    Deja View - the feeling that you've seen this post before.

    My blog | My articles

    M Offline
    M Offline
    Muigai Mwaura
    wrote on last edited by
    #21

    I'm cracking up :laugh: I'm shedding tears :(( the people I work with are looking at me like I'm crazy.

    1 Reply Last reply
    0
    • M Mitendra Anand

      Value-type objects such as structs are created on the stack, while reference-type objects such as classes are created on the heap. So it is actually a PASS - BY - REFERENCE Both types of objects are destroyed automatically, but objects based on value types are destroyed when they go out of scope, whereas objects based on reference types are destroyed at an unspecified time after the last reference to them is removed. Happy Coding! Mitendra

      J Offline
      J Offline
      jon_175
      wrote on last edited by
      #22

      The object is passed by value, but the what is actually passed since it is a reference object is a pointer to the object. So, the "value" that is actually passed is the pointer not the object and therefore any changes made through the pointer change the original object. What you can't change is the pointer itself. That is the "value". :)

      M 1 Reply Last reply
      0
      • J jon_175

        The object is passed by value, but the what is actually passed since it is a reference object is a pointer to the object. So, the "value" that is actually passed is the pointer not the object and therefore any changes made through the pointer change the original object. What you can't change is the pointer itself. That is the "value". :)

        M Offline
        M Offline
        Mitendra Anand
        wrote on last edited by
        #23

        You are right Jon. I see your point.

        1 Reply Last reply
        0
        • S Sherin Iranimose

          So If I print the value anywhere inside the Load function will only print 10. But it is not.... Its 30 after function call.

          EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE. How to post a question

          B Offline
          B Offline
          BillW33
          wrote on last edited by
          #24

          When the class object is passed into ChangeMyVar(MyClass objMyClass) it is passed by value. Saying it another way: a copy of the object is made and then used by the ChangeMyVar method. Since this is a copy any changes to it do not affect the original. Bill W

          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