Sunday 23 May 2010

Array Data Type

Array is a structured data type that can hold some data which has same data type. Every element in an array has an index and it can be individually accessed. In Pascal, we can have one-dimensional array or n-dimensional array.

To declare one-dimensional array that can hold six character, we can us this statement :

Type

    OneDimensionalArray = array[1..6] of char;

Var

    TheData : OneDimensionalArray;

Or you can use this statement :

 

Var

    TheData : array[1..6] of char;

The statement above declares an array that can hold six elements. It is called static array, because it has a fix amount of data. While a dynamic array does not have a fix amount of data.

To access an element in an array use this syntax :

ArrayVariableName[ArrayIndex];

Example :

TheData[3] := ‘A’;

Writeln(TheData[3]);

Readln(TheData[3]);

Example program :

program Project1;
{$APPTYPE CONSOLE}
uses
   SysUtils;
var
   i : integer;
   TheData : array[1..5] of char;
begin
   //assigning values to array
   TheData[1] := 'A';
   TheData[2] := 'B';
   TheData[3] := 'C';
   TheData[4] := 'D';
   TheData[5] := 'E';
   for i := 1 to 5 do writeln(TheData[i]);
   readln;
end.

You can download the complete code here.

4 comments:

  1. wow wow selalu ada info yang baru, makasih infonya

    moga sukses selalu

    ReplyDelete
  2. thank you pakde, for following the tutorial..

    ReplyDelete
  3. s The best and a lot of secret drop-shipping suppliers in the world which will provide your products globally available for you directly to your customers doors. Also get the best drop-shipping manufacturer on your organization.

    ReplyDelete

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.