WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Go - Call by value


The call with the aid of cost method of passing arguments to a feature copies the actual price of an issue into the formal parameter of the feature. Go programming language uses name via fee approach to skip arguments. Consider the function swap() definition as follows.
/* characteristic definition to swap the values */
func switch(int x, int y) int 
   var temp int

   temp = x /* save the cost of x */
   x = y    /* put y into x */
   y = temp /* placed temp into y */

   return temp;

allow us to call the feature switch() with the aid of passing real values as within the following instance
bundle major

import "fmt"

func fundamental() 
   /* nearby variable definition */
   var a int = 2 hundred
   var b int = 3500

   fmt.Printf("Before switch, value of a : %dn", a )
   fmt.Printf("Before change, price of b : %dn", b )

   /* calling a characteristic to change the values */
   swap(a, b)

   fmt.Printf("After change, fee of a : %dn", a )
   fmt.Printf("After change, cost of b : %dn", b )

func swap(x, y int) int 
   var temp int

   temp = x /* save the price of x */
   x = y    /* placed y into x */
   y = temp /* positioned temp into y */

   go back temp;

Put the above code in a single C record, after which assemble and execute it. It will produce the following end result
$move run important.Pass
Before switch, price of a : 200
Before change, cost of b : 3500
After switch, price of a : two hundred
After switch, price of b : 3500

It shows that there may be no change in the values even though they had been modified in the feature.