1.

Explain The Syntax To Create A Function In Go?

Answer»

The general FORM of a function definition in Go programming language is as follows −

func function_name( [parameter list] ) [return_types]
{
body of the function
}

A function definition in Go programming language consists of a function header and a function body. Here are all the parts of a function −

  • func func starts the declaration of a function.
  • Function Name − This is the actual name of the function. The function name and the parameter list together constitute the function signature.
  • Parameters − A parameter is LIKE a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.
  • RETURN Type − A function may return a list of values. The return_types is the list of data types of the values the function returns. Some functions PERFORM the desired operations without returning a value. In this case, the return_type is the not required.
  • Function Body − The function body contains a collection of statements that define what the function does.

The general form of a function definition in Go programming language is as follows −

func function_name( [parameter list] ) [return_types]
{
body of the function
}

A function definition in Go programming language consists of a function header and a function body. Here are all the parts of a function −



Discussion

No Comment Found