|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
Passing static arrays to proceduresWe have static arrays with various sizes and we want to pass them to a procedure that prints the elements.
Output in both cases: 2 7 4 7 2 1 0 9 In C, when we pass an array to a procedure, we pass the array and its length (the number of elements) to the procedure. In the procedure we get the number of elemnts and thus we can traverse the array. In Nim, on the formal parameter list, you can indicate We could write What is an openArray ?
So the following code is completely valid: proc show(arr: openArray[int]) = for e in arr: stdout.write(e, " ") echo "" let numbers1 = [2, 7, 4] # static array numbers2 = @[7, 2, 1, 0, 9] # seq, notice the @ sign show(numbers1) show(numbers2) The output is the same as shown above. |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |
||||