0% found this document useful (0 votes)
155 views

Arrays in Pascal

The document defines arrays and how to declare and populate them in a programming language. Key points: - An array is a variable that can store multiple elements of the same type. The size determines how many elements it can hold. - Elements have subscripts and are accessed using brackets. The array is declared with the size in brackets after the array name and data type. - Examples show declaring arrays to store student grades and salaries, and populating arrays with known and unknown values using loops or individual assignments.

Uploaded by

Kerry-Ann Cole
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views

Arrays in Pascal

The document defines arrays and how to declare and populate them in a programming language. Key points: - An array is a variable that can store multiple elements of the same type. The size determines how many elements it can hold. - Elements have subscripts and are accessed using brackets. The array is declared with the size in brackets after the array name and data type. - Examples show declaring arrays to store student grades and salaries, and populating arrays with known and unknown values using loops or individual assignments.

Uploaded by

Kerry-Ann Cole
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Objectives: Define the term array. Understand the term array size. Declare arrays Write elements to an array.

An array is a variable that can store a number of elements of the same type.
Item1 Milk Item2 Eggs Item3 Butter Item4 Juice

Element: is the bottom row of the array they all of the same type (string). They act as separate variables. Subscript: The subscript more like an address that is assigned to each element in the array. Item1, Item2, Item3, Item4 are all subscripts.

The size of the array determines the number of elements it can hold. Therefore if you need an Array to store 100 employees the size of the Array would be 100. The size of the array is specified in Braces [ ]. If an array has 100 elements the size would be specified as [1..100]

NOTE an array can only store variables of the same type.

In order to declare an ARRAY called item which stores 100 elements we would use the following syntax VAR <array name>: array [size] of datatype; item: array[1..100] of string; Remember the different data types are: String: Used for storing letters { Tom, JACK, Roye} Integer: Used for storing hole numbers { 1, 34,45} Real: Used for storing fractional numbers {1.33, 56.7,45.9}

1. Declare an array called test which store the grades for 25 students. 2. Declare an array called salary that stores the income received by 60 employees 3. Declare an array called student which stores the names of 25 students in information technology class. 4. Consider the following arrays state their name, size and datatype: Score: array[1..20] of real; Address: array[1..200] of string;

Suppose you wanted to store four marks in an array called score when you know before hand all the scores received by the student: Program arraystore; Var score: array[1..4] of integer; Begin Score[1]:= 89; Score[2]:= 99; Score[3]:= 23; Score[4]:= 78; Writeln(Score[1]); End.

Suppose you wanted to store four scores where the actual scores are unknown. You would be required to use a loop to write the values in an array. Program arraystore; Var score: array[1..4] of integer; i: integer; Begin for i:= 1 to 4 do Begin Writeln(Enter Students Mark); Readln(score[i]); end; End.

You might also like