Retrieving an Element of an Array: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
(revert spam)
Line 1: Line 1:
{{task}}
[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=164 alprazolam online] [http://wc1.worldcrossing.com/WebX/.1de60a09 viagra online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=69 albuterol online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/sagemringtones_756.htm free sagem ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=146 buy zanaflex] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3708 propecia online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/soma_9880.htm cheap soma] [http://library.cshl.edu/wp/vb/member.php?u=1356 order paxil] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30295 sildenafil online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=81 cyclobenzaprine online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=101 meridia online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=89 free funny ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=137 cheap valium] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=179 cheap fioricet] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30278 cheap nexium] [http://wc1.worldcrossing.com/WebX/.1de60a20 nexium online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30317 cheap zanaflex] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30333 free funny ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1377 free samsung ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a2b but ultracet] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=99 cheap lorazepam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=223 wellbutrin online] [http://wc1.worldcrossing.com/WebX/.1de609db but adipex] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30321 hgh online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3715 cheap vigrx] [http://users.wpi.edu/~dance/blahdocs/uploads/diazepam_6139.htm cheap diazepam] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3756 but lortab] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=71 buy alprazolam] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30332 tracfone ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=121 free real ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f2 meridia] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30347 free verizon ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=102 midi ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=130 free sonyericsson ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30269 cheap wellbutrin] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=113 paxil online] [http://library.cshl.edu/wp/vb/member.php?u=1347 cialis] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=91 hoodia online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=229 cheap valium] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=134 buy tramadol] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=105 mp3 ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=94 free jazz ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3739 buy ultram] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/alprazolam_413.htm alprazolam online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30334 mp3 ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2907 free sprint ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30279 ultracet online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30358 midi ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1386 mono ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=87 online flexeril] [http://wc1.worldcrossing.com/WebX/.1de609eb funny ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/monoringtones_7654.htm free mono ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2887 pharmacy online online] [http://students.hsc.unt.edu/housing/item.cfm?type=2869 lorazepam online] [http://students.hsc.unt.edu/housing/item.cfm?type=2889 cheap vigrx] [http://students.hsc.unt.edu/housing/item.cfm?type=2897 nokia ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30294 cheap prozac] [http://library.cshl.edu/wp/vb/member.php?u=1344 xanax online] [http://users.wpi.edu/~dance/blahdocs/uploads/phentermine_3757.htm phentermine] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=236 tracfone ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a29 buy tramadol] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=120 free qwest ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/clonazepam_3384.htm clonazepam online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30258 cheap vicodin] [http://students.hsc.unt.edu/housing/item.cfm?type=2858 cheap viagra] [http://library.cshl.edu/wp/vb/member.php?u=1383 free sagem ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a33 prozac online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30346 music ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a19 mp3 ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2857 ativan online] [http://library.cshl.edu/wp/vb/member.php?u=1355 cheap clonazepam] [http://wc1.worldcrossing.com/WebX/.1de609f1 cheap lortab] [http://wc1.worldcrossing.com/WebX/.1de609f8 free nokia ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30335 free nextel ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/valium_6454.htm cheap valium] [http://students.hsc.unt.edu/housing/item.cfm?type=2874 cheap ultracet] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3710 cheap clomid] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3773 free kyocera ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1354 cheap alprazolam] [http://library.cshl.edu/wp/vb/member.php?u=1374 free qwest ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/soma_5561.htm cheap soma] [http://students.hsc.unt.edu/housing/item.cfm?type=2888 lortab online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30237 valium online] [http://wc1.worldcrossing.com/WebX/.1de60a0c buy wellbutrin] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/cingularringtones_7013.htm cingular ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3772 midi ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a14 free jazz ringtones] [http://wc1.worldcrossing.com/WebX/.1de609ff free real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=125 free sharp ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=235 tenuate] [http://wc1.worldcrossing.com/WebX/.1de609ee cheap hydrocodone] [http://students.hsc.unt.edu/housing/item.cfm?type=2899 tracfone ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=196 free motorola ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3711 lisinopril online] [http://students.hsc.unt.edu/housing/item.cfm?type=2890 online zanaflex] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=204 cheap ortho] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=184 hoodia online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=128 sony ericsson ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=181 free free ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2864 clonazepam online] [http://students.hsc.unt.edu/housing/item.cfm?type=2892 rivotril online] [http://library.cshl.edu/wp/vb/member.php?u=1370 free tracfone ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/fioricet_2815.htm users.wpi.edu/~dance/blahdocs/uploads/
] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=195 free mono ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=188 cheap levitra] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/tracfoneringtones_5328.htm tracfone ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3713 cheap tenuate] [http://students.hsc.unt.edu/housing/item.cfm?type=2850 order phentermine] [http://wc1.worldcrossing.com/WebX/.1de60a11 diethylpropion online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30364 ericsson ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3746 ambien online] [http://wc1.worldcrossing.com/WebX/.1de609fb ortho online] [http://wc1.worldcrossing.com/WebX/.1de60a12 ericsson ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2884 celexa online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30331 free free ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30230 tramadol online] [http://students.hsc.unt.edu/housing/item.cfm?type=2859 meridia online] [http://students.hsc.unt.edu/housing/item.cfm?type=2870 cheap xenical] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30307 cheap zoloft] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/hydrocodone_3335.htm cheap hydrocodone] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=174 cyclobenzaprine online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3719 free nokia ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1351 buy adipex] [http://students.hsc.unt.edu/housing/item.cfm?type=2909 verizon ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=208 phentermine online] [http://students.hsc.unt.edu/housing/item.cfm?type=2915 mono ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30353 mono ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a0e cheap celexa] [http://students.hsc.unt.edu/housing/item.cfm?type=2883 lipitor online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/alltelringtones_474.htm free alltel ringtones] [http://wc1.worldcrossing.com/WebX/.1de609dd free alltel ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/clonazepam_4321.htm cheap clonazepam] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=144 xanax online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=148 zyban online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=119 punk ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2871 cheap wellbutrin] [http://students.hsc.unt.edu/housing/item.cfm?type=2866 levitra online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30298 lisinopril online] [http://library.cshl.edu/wp/vb/member.php?u=1352 norco online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=124 free samsung ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1353 vicodin] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=135 ultracet online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3700 norco] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30308 lipitor online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30315 buy lortab] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30310 tenuate online] [http://users.wpi.edu/~dance/blahdocs/uploads/nextelringtones_5134.htm nextel ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/lorazepam_17.htm lorazepam online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=199 free music ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=112 but ortho] [http://library.cshl.edu/wp/vb/member.php?u=1361 cheap xenical] [http://students.hsc.unt.edu/housing/item.cfm?type=2855 diazepam online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=68 buy adipex] [http://users.wpi.edu/~dance/blahdocs/uploads/samsungringtones_3147.htm free samsung ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/carisoprodol_7292.htm carisoprodol online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30297 cheap albuterol] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=162 free alltel ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3702 buy paxil] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3758 buy rivotril] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30263 levitra online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=142 wellbutrin online] [http://library.cshl.edu/wp/vb/member.php?u=1357 levitra online] [http://wc1.worldcrossing.com/WebX/.1de609ea free ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30314 buy pharmacy online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30240 carisoprodol online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/tramadol_3245.htm tramadol online] [http://wc1.worldcrossing.com/WebX/.1de609e6 cyclobenzaprine online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=103 mono ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30248 cheap ativan] [http://library.cshl.edu/wp/vb/member.php?u=1385 sony ericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a22 but phentermine] [http://students.hsc.unt.edu/housing/item.cfm?type=2901 free mp3 ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3769 sony ericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=127 soma online] [http://library.cshl.edu/wp/vb/member.php?u=1349 viagra online] [http://wc1.worldcrossing.com/WebX/.1de60a2c ultram] [http://wc1.worldcrossing.com/WebX/.1de60a10 cheap didrex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=111 order norco] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=224 sagem ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30345 sprint ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=76 online cialis] [http://wc1.worldcrossing.com/WebX/.1de60a05 sprint ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=234 sprint ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1381 polyphonic ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2873 nexium online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=92 cheap hydrocodone] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=226 cheap tramadol] [http://students.hsc.unt.edu/housing/item.cfm?type=2925 mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a34 sony ericsson ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2921 wwe ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=109 free nextel ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/funnyringtones_5351.htm funny ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3735 free mtv ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=227 ultracet online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=231 rivotril online] [http://wc1.worldcrossing.com/WebX/.1de60a1f lisinopril online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/xanax_4637.htm xanax online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30359 wwe ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3751 sildenafil online] [http://users.wpi.edu/~dance/blahdocs/uploads/ambien_6489.htm cheap ambien] {{task}}


In this task, the goal is to retrieve an element of an [[array]].
In this task, the goal is to retrieve an element of an [[array]].
Line 16: Line 15:
mov esi, array_offset
mov esi, array_offset
mov ebx, 2
mov ebx, 2
mov eax, [esi ebx*4]
mov eax, [esi+ebx*4]


==[[ActionScript]]==
==[[ActionScript]]==
Line 55: Line 54:
}
}
==[[C plus plus|C ]]==
==[[C plus plus|C++]]==
[[Category:C plus plus|C ]]
[[Category:C plus plus|C++]]


template<typename T>
template<typename T>
Line 140: Line 139:
Forth does not have special syntax for array access. Address arithmetic is used to access contiguous memory.
Forth does not have special syntax for array access. Address arithmetic is used to access contiguous memory.
create array 1 , 2 , 3 , 4 ,
create array 1 , 2 , 3 , 4 ,
array 2 cells @ . \ 3
array 2 cells + @ . \ 3


==[[IDL]]==
==[[IDL]]==

Revision as of 09:32, 20 July 2007

Task
Retrieving an Element of an Array
You are encouraged to solve this task according to the task description, using any language you may know.

In this task, the goal is to retrieve an element of an array.

4D

  ` first element
$elem:=$array{1}

X86 assembly

Assembler: nasm

mov esi, array_offset
mov ebx, 2
mov eax, [esi+ebx*4]

ActionScript

var arr:Array = new Array(1,2,3);
var myVar:Number = arr[1];
// the value of myVar is: 2

Ada

Array indexed by an enumerated type. Ada enumerated types are discrete non-numeric types.

type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
type Daily_Counts is array(Days) of Natural;
This_week : Daily_Counts := (200, 212, 175 220, 201, 120, 0);
Monday_Sales : Natural;
Monday_Sales := This_Week(Mon); 

Monday_Sales is assigned 200

AppleScript

on getArrayValue(array, location)
    -- very important -- The list index starts at 1 not 0
    return item location in array
end getArrayValue

C

 int array_index(int array[], int index) {
   return array[index];
 }

C#

 int getArrayValue( int values[], int index ) {
   return values[index];
 }
 

C++

 template<typename T>
 T array_index(T array[], size_t index) {
   return array[index];
 }

ColdFusion

<cfset arr = ArrayNew(1)>
<cfset arr[1] = "one">
<cfset arr[2] = "2">
<cfset arr[3] = 3>
<cfset var = arr[1]>

The value of var is "one"

ColdFusion Arrays are NOT zero-based, their index begins at 1

Common Lisp

  (defun array-value (array index)
    (aref array index))

Delphi/Object Pascal/Turbo Pascal/Standard Pascal

Array's in all the flavors of pascal can be of any valid base type, or user defined type ( which are all made up of base types ) and are multi-dimensional. With Delphi dynamic arrays were defined but had been used in pascal since its inseption.

A Static array defintion:

foo : array[1..10] of integer; { The base index is ONE }

The base index can be freely chosen:

foo: array[7 .. 16] of integer; { The base index is 7 }

Indeed, the "1 .. 10" resp. "7 .. 16" are actually types: they are integer subrange types. Arrays can also be indexed by enumeration types or enumeration subrange types:

type
 rainbowcolor = (red, orange, yellow, green, blue, violet);
var
 foo: array[rainbowcolor] of integer;
 bar: array[yellow .. blue] of integer;
 i: integer
begin
 i := foo[red]; { allowed indices are red, orange, yellow, green, blue, violet }
 i := bar[green]; { allowed indices are yellow, green, blue }
end;

A Dynamic Array type in Delphi:

foo : array of integer ; // The base index is ZERO

An "old school" dynamic array in the various flavors of pascal

foo : array[0..0] of integer;  // The base index is ZERO

A dynamic array in Extended Pascal:

type
 intarray(n: integer) = array[1 .. n] of integer; { base index 1 }
var
 foo: ^intarray;
begin
 new(foo, 10); { foo now has index 1 to 10 }
 i := foo[2];
 dispose(foo); { get rid of the array }
end;

In the case of the static array, the compiler generates the code to allocate the required memory to hold 10 integers.

In the Delphi style ---dynamic--- array you must set its length:

SetLength(foo,10);  // this array will no hold 10 integers

In the "old school" style of dynamic arrays, you created a point to the zero length declaration and then allocated memory to it with GetMem

pFoo : ^Foo ;
Foo  : array[0..0] of integer ;

All arrays are accessed the same way regardless of declaration method.

i : integer ;

i := foo[n] ;

where n is the array index who's base is either 1 or 0 depending on how it was declared.

Erlang

Erlang lists are 1-based which means that the index must be within the bounds (1 .. length(List)):

Value = lists:nth(Index, List).

Forth

Forth does not have special syntax for array access. Address arithmetic is used to access contiguous memory.

create array 1 , 2 , 3 , 4 ,
array 2 cells + @ .    \ 3

IDL

 ; this is allowed:
 result = arr(5) 
 ; but this is preferred:
 result = arr[5]

The form with square brackets is preferred as it unambiguously constitutes array access, while the version with round ones can conflict with a function call if there are both a function and an array with the same name arr.

Java

public Object getArrayElem(Object[] array, int pos) {
    return array[pos];
}

JavaScript

var element = array[index];

mIRC

Interpeter: mIRC Script Editor

Library: mArray Snippet

 alias readmyarray { echo -a $array_read(MyArray, 2, 3) }

Perl

Interpreter: Perl 5.8.8

$elem = $array[0];

PHP

$array = array('php', 'has', 'arrays');
// First element 
$elem  = $array[0];

Pop11

lvars ar = {1 two 'three'};
lvars elem;
;;; Access second element and assign to variable elem
ar(2) -> elem;

This example uses the simplest possible array (a vector). Pop11 has more general arrays, but in all cases access follows the same pattern, and look the same as procedure (function) call.

Python

Interpreter: Python 2.5

The item is an element in a list at a given index

 item = aList[index]

or

To use a list like a stack be it FIFO/LIFO

 aList.pop()  # Pop last item in a list
 aList.pop(0) # Pop first item in a list

Note: When using the pop() method, the element is removed from the list.

Ruby

 ary = ['Ruby','rules','big','time']
 #the first element
 element = ary[0]
 #or
 element = ary.first
 # => element = 'Ruby'
 #the last element
 element = ary[-1]
 #or
 element = ary.last
 # => element = 'time'
 #retrieving different values at once
 elements = ary.values_at(0,2,3)
 # => elements = ['Ruby','big','time']
 #select the first element of length 3
 element = ary.find{|el|el.length==3}
 # => element = "big"

Smalltalk

  "Retrieve second element of an array"
  index := 2
  element := anArray at: index

Tcl

All arrays in Tcl are associative. If "key" is the variable that holds the key of the element to be retrieved, then

 set result $array($key)

Toka

This retrieves the value 20 from the second item in the array:

 3 cells is-array table
 ( Populate the array )
 10 0 table put-element
 20 1 table put-element 
 30 2 table put-element
 
 table 1 get-element