In this program, we will pass an integer array as an argument in a user-defined function and modify the value of array elements and return the modified array to the calling function.
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.
In this program, we created a user defined function GetArray() to modify elements of array and return the modified array to the calling function, which is given below:
In the main() function, we created two arrays of integers intArr, retArr and then we read elements from the user. After that, we passed the created array to the GetArray() function, The GetArray() function modifies the value of the passed array and then returns the modified array to the calling function.
Program/Source Code:
The source code to return an array from a user-defined function is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.
In this program, we created a user defined function GetArray() to modify elements of array and return the modified array to the calling function, which is given below:
In the main() function, we created two arrays of integers intArr, retArr and then we read elements from the user. After that, we passed the created array to the GetArray() function, The GetArray() function modifies the value of the passed array and then returns the modified array to the calling function.
need an explanation for this answer? contact us directly to get an explanation for this answer