Debugger Exception Error and memory overshoot

前端 未结 1 1264
温柔的废话
温柔的废话 2021-01-29 11:02

I tried to run the following code but it shows an error regarding memory address and shows a message that \'n maybe undefined after the loop\'. Please have a look.



        
1条回答
  •  青春惊慌失措
    2021-01-29 11:58

    You don't allocate any memory for the arrays. You need to call to SetLength to do that.

    SetLength(r, n_max);
    // and likewise for the other arrays
    

    What's more, the loop does nothing. The loop contains a single statement which is an empty statement terminated by the semi-colon after the do.

    for n := 0 to n_max-1 do;
    // yes, that semi-colon is the end of the loop
    

    You'll need a begin/end block.

    for n := 0 to n_max-1 do
    begin
      // loop body goes in here
      ....
    end;
    // at this point, outside the loop, the value of n is ill-defined. 
    

    0 讨论(0)
提交回复
热议问题