Wednesday, 7 April 2021

Array Types Part 1 | PPL | Sebesta | Elementary Data Types in Programming Language

                 In this post, we will see Array Types Part 1 | PPL | Sebesta | Elementary Data Types in Programming Language | array types, data types in ppl, data types ppl, elementary data types in programming language, ppl, sebesta  

5. Array types


I. Definition:

              An array is a homogeneous aggregate of data elements in which an individual element is identified by its position in the aggregate, relative to the first element.



II. Arrays and Indices


              Specific elements of an array are referenced by means of a two-level syntactic mechanism, where the first part is the aggregate name, and the second part is a possibly dynamic selector consisting of one or more items known as subscripts or indices.


              The selection operation can be thought of as a mapping from the array name and the set of subscript values to an element in the aggregate. Indeed, arrays are sometimes called finite mappings.

              Symbolically, this mapping can be shown as

array_name(subscript_value_list) → element


              Generally, in most of the programming languages subscripts are bounded by brackets like []. But, in some programming languages, subscripts are bounded by parentheses like ().


              For Example, in Ada language

Sum := Sum + B(I);


              This results in reduced readability as parentheses are used for both subprogram parameters and array subscripts.

              Most languages other than Fortran and Ada use brackets to delimit their array indices.



              The type of the subscripts is often a subrange of integers, but Ada allows any ordinal type to be used as subscripts, such as Boolean, character, and enumeration. For example, in Ada one could have the following:


type Week_Day_Type is (Monday, Tuesday, Wednesday,

Thursday, Friday);

type Sales is array (Week_Day_Type) of Float;


              Range errors in subscripts are common in programs, so requiring range checking is an important factor in the reliability of languages.

              Many contemporary languages do not specify range checking of subscripts, but Java, ML, and C# do.

              By default, Ada checks the range of all subscripts, but this feature can be disabled by the programmer.



              Subscripting in Perl is a bit unusual in that although the names of all arrays begin with at signs ( @ ), because array elements are always scalars and the names of

scalars always begin with dollar signs ( $ ), references to array elements use dollar signs rather than at signs in their names. For example, for the array @list , the second element is referenced with $list [1].

              One can reference an array element in Perl with a negative subscript, in which case the subscript value is an offset from the end of the array.

              For example, if the array @list has five elements with the subscripts 0..4, $list [-2] references the element with the subscript 3.

              A reference to a nonexistent element in Perl yields undef , but no error is reported.

Watch following video:

Watch on YouTube:

No comments:

Post a Comment