受け取った配列への書き込み
明解C言語 入門編 > 6. 関数 >
受け取った配列への書き込み
Ruby
NINSU = 5 def int_set(no, vc) for i in 0..(no - 1) vc[i] = i end end ary = [] puts "関数 呼び出し前" for i in 0..(NINSU - 1) printf(" ary[%d] = %d\n", i, ary[i]) end int_set(NINSU, ary) puts "関数 呼び出し後" for i in 0..(NINSU - 1) printf(" ary[%d] = %d\n", i, ary[i]) end
実行結果
L:\>ruby l:\lesson_06_048.rb
関数 呼び出し前
ary[0] = 0
ary[1] = 0
ary[2] = 0
ary[3] = 0
ary[4] = 0
関数 呼び出し後
ary[0] = 0
ary[1] = 1
ary[2] = 2
ary[3] = 3
ary[4] = 4