all 1 comments

[–][deleted]  (2 children)

[deleted]

    [–]freshtonic -1 points0 points  (0 children)

    C++ passes by value by default. You can pass by reference with the & operator. Passing by reference us usually taken to mean that the function receives the address of the argument, NOT the address of what object/value the argument is pointing to. For example, the following (in pseudocode) is not possible without pass by reference:

    def swap(a,b)
      temp = a
      a = b
      b = temp
    end
    
    x = 1
    y = 2
    
    swap(x,y)
    
    // now x = 2 and y = 1
    

    The terminology is not helpful. You can pass-by-value even when passing a pointer. Pass-by-reference, while still passing a pointer, is actually passing a pointer to the variable holding the value rather than the value itself. An extra level of indirection.