[Pascal – TUT] Posts 5: Arrays

1. Concept

Arrays (Array) is a set of fixed elements of the same type called type element. The element type can be scalar type, String, type collections, kiểu Record.

[qads]

2. Arrays 1 evening

a. Declare
How to 1:

		TYPE <tên kiêu mảng>=ARRAY[index] OF <kiểu phàn tử>;
		WHERE <tên biến mảng>:<tên kiểu mảng>;

How to 2:

		WHERE <tên biến mảng>:ARRAY[index] OF <kiểu phần tử>;

Wherein the child must be a domain type, scalar type listed, char or boolean. {However. people often use the domain type of integers is easy to imagine because it most closely resembles the concept of mathematical indicators.}
Example:

or:

		VAR		A: Array[1..5] of Integer;
				C: Array[Byte] of Char;

Direct declaring seems simple and concise than declaring indirect but many TH're required to use indirect ways to declare.

b. How to access

{fast access to each element of the array substrate data processing as well as the names we call our classes}
Each element of the array is accessed through an array variable name with the index of the array in braces [].
Example: The[1], The[2],…
Attention: Two arrays A and B have the same number of elements and element types, we can replace the entire element A by the corresponding elements of B by an assignment A := B.

3. Multidimensional Arrays

the. Declare
How to 1:

		TYPE <tên kiêu mảng>=ARRAY[chỉ số 1, chỉ số 2] OF <kiểu phàn tử>;
		VAR <tên biến mảng>:<tên kiểu mảng>;

How to 2:

		VAR <tên biến mảng>:ARRAY[chỉ số 1, chỉ số 2] OF <kiểu phần tử>;

Index 1 and indicators 2 is the index of rows and columns, they are separated by commas

Example:

		TYPE Mangnguyen = Array[1..5,1..3] of Integer;
		VAR		A: Mangnguyen;

or:

		VAR		A: Array[1..5,1..3] of Integer;

After declaring the array A will be 5 goods and 3 post.
Attention: Arrays 2 dimensional matrix aka.

b. How to access
To access the row i column j element we write A[in,j] or a[in][j].
Example: The[1,2], The[2][5].


Original article: vietsource.net