function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravikale
    New Member
    • Sep 2007
    • 1

    function

    What is the diffrence between function call by valu and call by refrence.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    As you have posted a question in the articles setion it is being moved to the Software Development Forum.

    MODERATOR.

    Comment

    • Stwange
      Recognized Expert New Member
      • Aug 2007
      • 126

      #3
      The difference is concerned with how parameters are passed to a function. With call by reference, any parameters passed refer to the actual variable, whereas with call by value the parameters refer to the VALUE of the variable, not the variable itself. Consider the following example:

      Code:
      int mainProgram()
          int x = 3;
          addOne (x);
          return x;
      End
      
      void addOne(int x)
          x = x + 1;
      End
      If this programming language uses pass by value by default, mainProgram will return 3, because addOne doesn't affect the original value of x.
      However, if it uses pass by reference, mainProgram will return 4 (as addOne incremented the variable, not just the value).

      Hope this helps. (If not, hopefully someone else will be able to explain it to you better)

      Comment

      Working...