title: Pascal procedure pass variable arrays
body: <p>When I try to pass variable arrays from procedure to the main program, <code>a[1]</code> in the procedure was supposed to be equal to <code>arr[1]</code> in the main program, like this:</p>
  
  <p><code>a[1] = arr[1]</code></p>
  
  <p><code>a[2] = arr[2]</code></p>
  
  <p><code>a[3] = arr[3]</code></p>
  
  <p><code>a[4] = arr[4]</code></p>
  
  <p><code>a[5] = arr[5]</code></p>
  
  <p>But the program actually acta like this:</p>
  
  <p><code>a[1] = ''</code></p>
  
  <p><code>a[2] = arr[1]</code></p>
  
  <p><code>a[3] = arr[2]</code></p>
  
  <p><code>a[4] = arr[3]</code></p>
  
  <p><code>a[5] = arr[4]</code></p>
  
  <p>I don't know what's wrong to the code, can someone point out the mistake?</p>
  
  <p>The simplied code, same problem:</p>
  
  <pre><code>var
    arr : array[1..5] of string;
    i : integer;
  
  procedure test(var a : array of string);
  var
    i : integer;
  begin
    a[1] := 'one';
    a[2] := 'two';
    a[3] := 'three';
    a[4] := 'four';
    a[5] := 'five';
    for i := 1 to 5 do writeln(a[i]);
  end;
  
  begin
    test(arr);
    write('-----');
    for i := 1 to 5 do
    begin
      writeln(arr[i]);
      if arr[i] = '' then writeln('NOTHING');
    end;
    readln
  end.
  </code></pre>