In Go programming language, you can create a function using the func
keyword followed by the function name, parameters inside the parentheses (if any), and the function body. Here's an example of a simple function that takes two string parameters and returns their concatenation:
main.go84 chars4 lines
In the above code, func
is the keyword to declare a function, concatenateStrings
is the function name, str1
and str2
are the parameter names with their respective data types, and string
is the return type of the function.
To call this function, you simply need to pass two string values to it, like this:
main.go93 chars3 lines
In this case, the result will be the concatenated string "Hello World!" displayed on the console using the Println()
function.
gistlibby LogSnag