EASY Passing Variables by Value
func main() {
x := 5
increment(x)
fmt.Println(x)
// still prints 5,
// because the increment function
// received a copy of x
}
func increment(x int) {
x++
}func main() {
x := 5
increment(x)
fmt.Println(x)
// still prints 5,
// because the increment function
// received a copy of x
}
func increment(x int) {
x++
}package main
func monthlyBillIncrease(costPerSend, numLastMonth, numThisMonth int) int {
lastMonth := getBillForMonth(costPerSend, numLastMonth)
thisMonth := getBillForMonth(costPerSend, numThisMonth)
return thisMonth - lastMonth
}
func getBillForMonth(costPerSend, messagesSent int) int {
return costPerSend * messagesSent
}