Functions
This is a simple Go program that defines two functions for addition and demonstrates their usage in the main function.
Output
Now, let's break down the code and explain each part:
Function Declarations:
plus(a int, b int) int
: This function takes two integers (a
andb
) as parameters and returns their sum.plusPlus(a, b, c int) int
: This function takes three integers (a
,b
, andc
) as parameters and returns their sum.
Main Function:
main()
: This is the entry point of the program.res := plus(1, 2)
: Calls theplus
function with arguments 1 and 2, and stores the result in the variableres
.fmt.Println("1+2 =", res)
: Prints the result of the addition operation.res = plusPlus(1, 2, 3)
: Calls theplusPlus
function with arguments 1, 2, and 3, and stores the result in the variableres
.fmt.Println("1+2+3 =", res)
: Prints the result of the addition operation.
Last updated
Was this helpful?