OneBite.Dev - Coding blog in a bite size

call a function with parameter in Go

Code snippet on how to call a function with parameter in Go

package main

import "fmt"

func add(a, b int) int {
  return a + b
}

func main(){
  sum := add(10, 15)
  fmt.Println(sum)
}

This code is written in Go. It has two functions; add() and main(). The add() function takes two parameters, a and b, and returns the sum of both a and b. The main() function calls the add() function by passing in two values, 10 and 15. The value of sum is assigned the returned value of add(). Finally, the result is printed by using fmt.Println(). In summary, this code adds 10 and 15 and prints the result.

go