Hello everybody. Please tell me how in Pascal (the most common) to make an array of variable length? Those. so that the user himself entered its length from the keyboard. I could not find anything on the Internet, so I ask a question here. And one more question: how, using ONLY html and javascript, print the length of the array from the body of the script. The array is called 'a'. If not difficult, give the whole piece of code.

  • one
    it is strange that you did not find anything on the Internet. - megacoder
  • The question is closed. - Uranium_235

3 answers 3

using ONLY html and javascript, print the length of the array from the body of the script. The array is called 'a'. If not difficult, give the whole piece of code.

Write on page:

<script type="text/javascript"> var a = [1, 2, 3, 4, 5]; //создали массив из цифр от 1 до 5 document.write('Длина массива = '); document.write(a.length); </script> 
  • Thank you, it works. And you can make it so that when the length is displayed, a new page does not open, but simply the line "Array length .. elements" is displayed in the same block (site on the page)? - Uran_235
  • The code that I wrote does not cause the opening of a new page (perhaps this happens for another reason). Give the code, just the script, try to figure it out ... - megacoder
  • Take a separate element to display the result: <div id = "rezult"> </ div>, and then do so: document.getElementById ('rezult'). InnerHTML = 'blablabla:' + a.length + 'symbols'; - ling
  • Probably what you call a new page is your own page. Simply document.write wipes it entirely if called after the onload event. - Artem Sapegin
  • ABOUT! Your option is working, ling. Thanks to everyone, the question is closed (and about arrays too). - Uran_235

Please tell me how in Pascal (the most common) to make an array of variable length? Those. so that the user himself entered its length from the keyboard. I could not find anything on the Internet, so I ask a question here

  1. In Pascal, as in any normal :-) language, you can use pointers. Cons - in Pascal work with pointers made inconvenient.
  2. You can make the type of the array, the size is obviously larger than necessary in practice. And then just use a piece of the array. Cons - a serious waste of excess memory. But it is convenient.
  3. You can use "open arrays" . But this is not a classic pascal already. Cons - tied to the type of compiler and compile options.
  • M-yes. You answered as a real programmer. Simple, understandable and unfortunately, almost useless =) I still almost did not understand anything. - Uranium_235
  • The only thing I can do is use the second option. - Uranium_235
  • The second option went best. I accept your answer. - Uranium_235
  • Then please mark the answer as accepted :-) - gecube
  • It seems to have clicked on the check mark. But there is some cropped alert pops up. Now look at the source. But there is no content of this alert. Now I learned that it says: "This question has already reached the limit of accepted answers." - Uranium_235

Please tell me how in Pascal (the most common) to make an array of variable length? Those. so that the user himself entered its length from the keyboard. I could not find anything on the Internet, so I ask a question here

a is an array of variable length

announcement:

 var a : array of longint; 

setting the size of n elements:

 SetLength(a, n); 

well, so that the whole code is with dynamic memory capture:

announcement:

 var a : array of ^longint; 

setting the size of n elements:

 SetLength(a, n); 

setting the value of 10 elements with the number i :

 New(a[i]); a[i]^ := 10; 

do not forget about the release of memory:

 Dispose(a[i]); 
  • 2
    As noted above, this is not the “most ordinary pascal”, i.e. not Pascal Wirth, and not even ANSI-pascal of the last millennium. - alexlz