Golang Program that uses func as Local Variable Last Updated : 26 May, 2020 Comments Improve Suggest changes Like Article Like Report Function performs a specific task, section of code that defined once can be reused. Functions are used to make your code easier to understand by breaking it into small and understandable tasks.Functions are also known as method, sub-routine, or procedure. General form of a function definition in Go programming language is given below- func function_name( [parameter list] ) [return_types] { body of the function } A function definition in Go programming language, here define some parts of a function- Func: Starts the declaration of a function. Function Name: Function names include parentheses and may include parameters.It is the actual name of the function. Parameters: A parameter is a named entity in a function definition, specifying an argument that the function can accept. Parameters are optional; that is, a function may contain no parameters. Return Type: The return data type must be specified as well.The return_types is the list of data types of the values the function returns. Function Body: It contains a collection of statements that define what the function does. To call a function, it needs to pass the required parameters along with its function name. This function takes two parameters number1 and number2 and returns the maximum value between the two? Example C package main import "fmt" func main() { // local variable definition var x int = 150 var y int = 360 var ret int // calling a function to get max value // and storing its value in a variable ret = max(x, y) fmt.Printf("Maximum value is : %d\n", ret) } // function returning the max between two numbers func max(number1, number2 int) int { var result int if number1 > number2 { result = number1 } else { result = number2 } return result } Output: Maximum value is : 360 We can pass the func variable as an argument to a method which requires a func argument as shown in the below example C // Golang program that uses func // as a local variable package main import ( "fmt" "strings" ) func main() { // assigning function f to a variable f1 f1 := func(f rune) bool { // Return true if underscore // or space rune. return f == '_' || f == ' ' } val := "geeks1 geeks2" // Pass func object to IndexFunc method. // Here f1 is a function argument finalresult := strings.IndexFunc(val, f1) fmt.Println(finalresult) val = "geeks1_geeks2" finalresult = strings.IndexFunc(val, f1) fmt.Println(finalresult) } Output: 6 6 Comment More infoAdvertise with us Next Article Golang Program that uses func as Local Variable S shivanisinghss2110 Follow Improve Article Tags : Go Language Golang-Program Similar Reads Golang program that uses func with variable argument list In Golang, a function that can be called with a variable argument list is known as a variadic function. One can pass zero or more arguments in the variadic function. If the last parameter of a function definition is prefixed by ellipsis ..., then the function can accept any number of arguments for t 2 min read Golang program that uses func with two arguments Functions may use certain parameters to receive values and perform the task required accordingly. The syntax for a function with two arguments is: func function_name( [parameter_1 parameter_2] ) [return_types] { body of the function } Example 1: Without any return type C // Golang program that uses 1 min read Golang Program that Uses Multiple Return Values In Golang, we can return multiple values at a time from a single function. Multiple return values can be achieved by changing the return type of the function in the function signature. Syntax :Â func value( ) ( int , int ) {Â return 1 , 0 ;Â }Â The (int, int) in this function signature explains that 2 min read Golang program that uses structs as map keys A map in Golang is a collection of unordered pairs of key-value. It is widely used because it provides fast lookups and values that can retrieve, update or delete with the help of keys. Syntax: map[Key_Type]Value_Type{} Example: var sample map[string]int Here the sample is a map that has a string as 6 min read How to declare and access pointer variable in Golang? Pointers in Go programming language or Golang is a variable which is used to store the memory address of another variable. Pointers in Golang is also termed as the special variables. The variables are used to store some data at a particular memory address in the system. The memory address is always 3 min read Naming the Return Values of a Function in Golang A return value helps to retain the final output of the function after it performs the instructions given in its body. Functions in Golang exhibit variety in return values and rely on the programmer to decide whether to name them or not. Golang introduces a concept of "Naked Return" allowing the use 3 min read Golang Tutorial - Learn Go Programming Language This Golang tutorial provides you with all the insights into Go Language programming, Here we provide the basics, from how to install Golang to advanced concepts of Go programming with stable examples. So, if you are a professional and a beginner, this free Golang tutorial is the best place for your 10 min read Function that takes an interface type as value and pointer in Golang Functions are generally the block of codes or statements in a program that gives the user the ability to reuse the same code which ultimately saves the excessive use of memory, acts as a time saver and more importantly, provides better readability of the code. So basically, a function is a collectio 2 min read time.Time.Local() Function in Golang with Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Local() function in Go language is used to find "t" with the location that is set to local time. Moreover, this function is defined under the time package. Here, you need to import the "time" packa 2 min read Different Ways to Find the Type of Variable in Golang Variable is a placeholder of the information which can be changed at runtime. And variables allow to Retrieve and Manipulate the stored information. There are 3 ways to find the type of variables in Golang as follows: Using reflect.TypeOf Function Using reflect.ValueOf.Kind() Function Using %T with 2 min read Like