Dale - Computer Science Illuminated 287

Dale - Computer Science Illuminated 287 - 260 Chapter 8...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 260 Chapter 8 High-Level Programming Languages Language Ada VB.NET C++/Java Array Declaration X‘S" I9 "67Ne9 " o =e9 " "hh"Yi X‘S" F"97Fz 9 o o e==e‘ ?I9 "67Ne9 "B D— I9X" "=i W F"9Fz 9 o?"YB .o I9X" "= 9X X"9Fz 9 oL"YMi LYM L"M L’M L(M LJM L:M LNM LfM L8M LKM "YNN "JK’ "NN8 "KJ: "Kf’ ":"Y KKK "YY" ’" ’YY" Ada allows the programmer to specify how the ten items are to be accessed. In this example I9 "67Ne9 " is defined as "hh"Y and is used to define the array. The result of this combination of statements is that an array of ten items is defined and is to be accessed using an index that ranges from "hh"Y. In VB.NET, C++, and Java, the declaration specifies the number of elements in the array, but the accessing occurs using the values Y to K. Let’s look at a drawing of this array with values already stored in the individual cells. See Figure 8.8. An array variable can be passed as a parameter and each individual cell can be accessed. How are the individual places in the array accessed? By giving the array name followed by an index. Here is how the three languages access the third and the last (tenth) cell. Language Figure 8.8 Array variable X"9Fz 9 o accessed from YhhK Array Access M\X?IX" M\X?IX" E> F"97Fz 9 o?(BBi E> F"97Fz 9 o?"YBBi Ada VB.NET C++ Java 3o =D6?F"9Fz 9 o?’BB 3o =D6?F"9Fz 9 o?KBB PD\X << F"9Fz 9 oL’Mi PD\X << F"9Fz 9 oLKMi J‘oX" hD\XhS= 9X?X"9Fz 9 oL’MBi J‘oX" hD\XhS= 9X?X"9Fz 9 oLKMBi A variable in a record and a variable in an array are treated exactly like any other variable. Only the accessing is different. In a record, variable access is by name; in an array, variable access is by an index that specifies which item in the collection you want. ...
View Full Document

Ask a homework question - tutors are online