Swift Program to Return an Array From a User-Defined Function

You are currently viewing Swift Program to Return an Array From a User-Defined Function

Swift program to return an array from a user-defined function

// Swift program to return an array 
// from a user-defined function

import Swift

func RetArr(arr:Array<Int>) -> Array<Int>{
var arr1 = arr

arr1.append(6)
arr1.append(7)
arr1.append(8)

return arr1
}

let arr:[Int] = [1,2,3,4,5]
var retArr = RetArr (arr:arr)

print(retArr)

Output

[1, 2, 3, 4, 5, 6, 7, 8]

...Program finished with exit code 0
Press ENTER to exit console.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply