02.07.2013 Views

The turbo

The turbo

The turbo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13 Arrays Part 2<br />

what you want to fill it with-O, which is Drd(False), that is, the<br />

numeric equivalent of False. Now you just need the length in<br />

bytes ... which brings you to the next procedure: SizeD'. SizeD'<br />

can take as its argument any variable or the name of any data<br />

type.lt returns the size of that variable (or of a variable of that<br />

type) in bytes. So, to initialize Base, you could write:<br />

FillChar(Base,8izeOf(Base) ,0);<br />

This statement will set all bits and bytes in Base = to o. <strong>The</strong><br />

combination of FiIIChar and SizeD' is a hard one to beat,<br />

especially for array initialization.<br />

13.3 ORDER OF ELEMENTS<br />

<strong>The</strong> elements of an array are stored in a specific order. <strong>The</strong> order<br />

is different for CP/M-SO systems than for all other version of<br />

TURBO Pascal. <strong>The</strong> following description applies to all versions<br />

of TURBO Pascal except CP/M-SO:<br />

If the array is one-dimensional-that is, if it has only one indexthen<br />

the elements are stored in ascending order. For example,<br />

the array List (defined as array[O .. 9] of Integer) stores its<br />

elements in the order List[O], List[1], List[2], and so on ... basically<br />

what you would expect. But what about multi-dimensional<br />

arrays? <strong>The</strong> array Stars is defined as<br />

var<br />

Stars : array[XRange,YRange] of O .. StarMa.x;<br />

where SRange = 1 ... S. So, the question is, are the elements in<br />

Stars stored as Stars[1, 1], Stars [2, 1], Stars[3, 1], etc., or are they<br />

stored as Stars[1,1], Stars[1,2], Stars[1,3], and so on? Pascal<br />

itself gives you the answer to that question. Remember that your<br />

definition above is just shorthand for<br />

array[XRange] of array[YRange] of O .. Starma.x;<br />

13-6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!