1Dimensional arrays

A 1 Dimensional array is a series of objects all of which are the same size and type. Each object in an array is called an array element. For example, you could have an array of integers or an array of characters or an array of anything that has a defined data type. The important characteristics of an array are:

  • Each element has the same data type (although they may have different values).
  • The entire array is stored contiguously in memory (that is, there are no gaps between elements).

Arrays can have more than one dimension. A one-dimensional array is called a vector ; a two-dimensional array is called a matrix.
Here is an example program that allows the user to enter up to 30 programs (allowing them to specify within that how many they want), then it allows them to pick a number to show the name that corrosponds to that number.

program arraysstudentno;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,crt
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };

{$R *.res}
var
students:array[1..30] of string;
nostudents:integer;
x:integer;
studentno:integer;
begin
writeln(‘How many students would you like to enter?’);
readln(nostudents);
for x:=1 to nostudents do
begin
writeln(‘Enter your students now, press enter between each name’);
readln(students[x]);
end;
writeln(‘Enter the name of the student you wish to see’);
readln(studentno);
writeln(students[studentno]);
readln;
end.