Creating an Array: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
Line 1: Line 1:
[http://polex.com.cn/resources/articles/cavalletta.htm cavalletta] [http://joperan.org/data/cuffia-clip/ cuffia clip] [http://veggis.org.cn/resources/articles/racconti-incesto.htm racconti incesto famiglia] [http://manoke.cn/topic/microsoft-windows/ microsoft windows xp media] [http://primonona.info/content/view/formato-a/ formato a2 stampanti] [http://xionny.cn/topic/oy-asiye/ oy asiye] [http://xionny.cn/topic/moon/ moon] [http://funkall.us/images/small/gioco-piscina/ gioco piscina] [http://svike.info/view/new/last-minute.htm last minute extra convenienti per agosto] [http://budget7i.info/lib/ink-film/ ink film telecom leonardo] [http://funkall.us/images/small/drinn/ drinn] [http://primonona.info/content/view/thomson-dm/ thomson dm 182] [http://soler.net.cn/data/bear-man.htm bear man] [http://manoke.cn/topic/euro/ euro 204] [http://wedner.info/content/view/samsung-hdd.htm samsung hdd] [http://polex.com.cn/resources/articles/dalmata.htm dalmata] [http://sneck.info/data/photos-de/ photos de chien] [http://funkall.us/images/small/digi-cam/ digi cam] [http://funkall.us/images/small/apple-ipod/ apple ipod mini] [http://budget7i.info/lib/saintriquier/ saint-riquier] [http://klohy.info/img/styles/vignette-sexy.htm vignette sexy] [http://budget7i.info/lib/batteria-siemens/ batteria siemens 700 mah] [http://primonona.info/content/view/crociera-po/ crociera po] [http://primonona.info/content/view/devil-may/ devil may cry 2] [http://klohy.info/img/styles/ruben-blades.htm ruben blades y willie colon] [http://svike.info/view/new/hard-drive.htm hard drive case] [http://wedner.info/content/view/sony-stampante.htm sony stampante a sublimazione] [http://sneck.info/data/bambola-club/ bambola club pornostar] [http://svike.info/view/new/lcd-rzla.htm lcd rz20la90] [http://joperan.org/data/vacanze-nel/ vacanze nel mondo] [http://joperan.org/data/ghisellini-milena/ ghisellini milena] [http://svike.info/view/new/lavatrici-classe.htm lavatrici classe a efficacia lavaggio] [http://wedner.info/content/view/central-lancashire.htm central lancashire] [http://joperan.org/data/vino-giordano/ vino giordano] [http://primonona.info/content/view/processore-amd/ processore amd schede madri] [http://budget7i.info/lib/un-po/ un po di storia dei beatles] [http://manoke.cn/topic/luccio-dalla/ luccio dalla] [http://joperan.org/data/canon-mini/ canon mini dv] [http://wedner.info/content/view/sedere-ragazza.htm sedere ragazza dj] [http://klohy.info/img/styles/sesso-genova.htm sesso genova] [http://veggis.org.cn/resources/articles/battag.htm battag] [http://budget7i.info/lib/tehrigarhwal/ tehri-garhwal] [http://budget7i.info/lib/albor-srl/ albor srl] [http://veggis.org.cn/resources/articles/usb-pc.htm usb pc800] [http://xionny.cn/topic/grouper/ grouper] [http://veggis.org.cn/resources/articles/porno-amatoriali.htm porno amatoriali] [http://veggis.org.cn/resources/articles/o-thou.htm o thou that tellest good tidings to zion] [http://svike.info/view/new/invia-mms.htm invia mms] [http://budget7i.info/lib/devoto-oli/ devoto oli dizionario lingua italiana] [http://svike.info/view/new/microsoft-xp.htm microsoft xp pro ita oem] [http://budget7i.info/lib/residence-in/ residence in italia] [http://manoke.cn/topic/tv-al/ tv al plasma e lcd philips] [http://soler.net.cn/data/lettore-mp.htm lettore mp3 panasonic] [http://polex.com.cn/resources/articles/tavolo-pranzo.htm tavolo pranzo] [http://funkall.us/images/small/spalla-atleta/ spalla atleta] [http://primonona.info/content/view/tomtom-maps/ tomtom maps of western europe] [http://svike.info/view/new/les-deux.htm les deux alpes] [http://joperan.org/data/bred-easy/ bred easy] [http://klohy.info/img/styles/motherboard-micro.htm motherboard micro atx] [http://veggis.org.cn/resources/articles/cimat.htm cimat] [http://funkall.us/images/small/lcd-portatile/ lcd portatile dvd] [http://budget7i.info/lib/nostalgia-di/ nostalgia di un piccolo grande amore] [http://funkall.us/images/small/toshiba/ toshiba 740] [http://svike.info/view/new/lcd.htm lcd 37] [http://budget7i.info/lib/pony/ pony] [http://budget7i.info/lib/pizzerie-firenze/ pizzerie firenze] [http://joperan.org/data/miramare-di/ miramare di rimini] [http://budget7i.info/lib/mango-visto/ mango visto cosi] [http://polex.com.cn/resources/articles/tavolo-cornilleau.htm tavolo cornilleau] [http://manoke.cn/topic/hatteria/ hatteria] [http://soler.net.cn/data/televisori-con.htm televisori con lettore dvd] [http://polex.com.cn/resources/articles/digilander.htm digilander] [http://klohy.info/img/styles/nike-total.htm nike total 90] [http://klohy.info/img/styles/codici-wafer.htm codici wafer seca1] [http://klohy.info/img/styles/indottrinamento.htm indottrinamento] [http://veggis.org.cn/resources/articles/vecchia-russia.htm vecchia russia] [http://soler.net.cn/data/la-faccia.htm la faccia dell ignoranza] [http://sneck.info/data/drag/ drag] [http://soler.net.cn/data/xxt-agp.htm x850xt agp] [http://wedner.info/content/view/straight-shooting.htm straight shooting] [http://veggis.org.cn/resources/articles/www-pattayalivecam.htm www pattayalivecam com] [http://soler.net.cn/data/digiland-libero.htm digiland libero] [http://polex.com.cn/resources/articles/singol-donne.htm singol donne] [http://soler.net.cn/data/claudio-abbado.htm claudio abbado. brahms, violin concert. dvorak, symphony no. 9, from new world] [http://sneck.info/data/teenme-com/ teenme com] [http://budget7i.info/lib/poppin-dem/ poppin dem thangs] [http://wedner.info/content/view/elisa-cd.htm elisa cd musicali] [http://svike.info/view/new/camping-jesolo.htm camping jesolo] [http://klohy.info/img/styles/bernhardi-august.htm bernhardi, august ferdinand] [http://primonona.info/content/view/fanghi-di/ fanghi di guam] [http://wedner.info/content/view/negozi-scout.htm negozi scout brescia] [http://polex.com.cn/resources/articles/hot-chocolate.htm hot chocolate 14 greatest hits] [http://polex.com.cn/resources/articles/mysinka.htm mysinka] [http://veggis.org.cn/resources/articles/lacrime-di.htm lacrime di pioggia di venditti] [http://manoke.cn/topic/pascali-pino/ pascali pino libri] [http://veggis.org.cn/resources/articles/notre-dame.htm notre dame cocciante] [http://klohy.info/img/styles/logos.htm logos 584] [http://wedner.info/content/view/amicizia-tema.htm amicizia tema] [http://polex.com.cn/resources/articles/giochi-con.htm giochi con palline] [http://funkall.us/images/small/old-matura/ old matura] [http://klohy.info/img/styles/richard-ashcroft.htm richard ashcroft lonely soul] [http://polex.com.cn/resources/articles/cartoline-romantiche.htm cartoline romantiche] [http://manoke.cn/topic/quotazioni-fondi/ quotazioni fondi investimento] [http://primonona.info/content/view/gogli-com/ gogli com] [http://manoke.cn/topic/da-tavolo/ da tavolo orologi] [http://joperan.org/data/the-smashing/ the smashing pumkins] [http://veggis.org.cn/resources/articles/hp-dat.htm hp dat 12 24] [http://xionny.cn/topic/jacksonville-hotel/ jacksonville hotel] [http://budget7i.info/lib/indesit-silver/ indesit silver r24s] [http://wedner.info/content/view/star-wars.htm star wars lego] [http://polex.com.cn/resources/articles/sexxxys.htm sexxxys] [http://funkall.us/images/small/my-heard/ my heard will go on] [http://svike.info/view/new/proliant-dl.htm proliant dl360] [http://klohy.info/img/styles/ragazza-tettona.htm ragazza tettona] [http://svike.info/view/new/chat-per.htm chat per adulti] [http://manoke.cn/topic/panini-spa/ panini spa] [http://wedner.info/content/view/smash-mouth.htm smash mouth u] [http://manoke.cn/topic/perlman/ perlman] [http://budget7i.info/lib/inni-sardi/ inni sardi] [http://klohy.info/img/styles/cura-acne.htm cura acne] [http://klohy.info/img/styles/lombra-sul.htm lombra sul tetto] [http://xionny.cn/topic/creme-cellulite/ creme cellulite] [http://soler.net.cn/data/geoff-crammonds.htm geoff crammonds grand prix 4] [http://budget7i.info/lib/video-hard/ video hard] [http://soler.net.cn/data/temrjuk.htm temrjuk] [http://manoke.cn/topic/hentai-puzle/ hentai puzle] [http://sneck.info/data/sistema-solar/ sistema solar] [http://wedner.info/content/view/traduzione-latino.htm traduzione latino nepote] [http://soler.net.cn/data/sister-act.htm sister act] [http://primonona.info/content/view/moto-guzzi/ moto guzzi v11 sport] [http://veggis.org.cn/resources/articles/kodak-easyshare.htm kodak easyshare dock] [http://primonona.info/content/view/dvd-verbatim/ dvd verbatim datalife plus azo] [http://soler.net.cn/data/billie-joe.htm billie joe] [http://sneck.info/data/fica-rasata/ fica rasata sborrata] [http://polex.com.cn/resources/articles/hora.htm hora] [http://polex.com.cn/resources/articles/barbie-sfilate.htm barbie sfilate] [http://svike.info/view/new/lampada-per.htm lampada per giardino] [http://sneck.info/data/nino-d/ nino d angelo senza giacca e cravata mp3] [http://veggis.org.cn/resources/articles/amphisbaena.htm amphisbaena] [http://wedner.info/content/view/www-unilibro.htm www unilibro it] [http://primonona.info/content/view/sony-dcr/ sony dcr dvd 7e] [http://klohy.info/img/styles/zion-y.htm zion y lenox track 16] [http://sneck.info/data/vacanza-mare/ vacanza mare rimini] [http://joperan.org/data/tally/ tally 9025] [http://veggis.org.cn/resources/articles/account-splitting.htm account splitting per dark age of camelot] [http://budget7i.info/lib/joyce-kelvin/ joyce kelvin irish lottery] [http://wedner.info/content/view/altri-tempi.htm altri tempi] [http://budget7i.info/lib/km-bmw/ km0 bmw 120d auto km 0] [http://manoke.cn/topic/la-mano/ la mano lunga del padrino] [http://wedner.info/content/view/neverne-bebe.htm neverne bebe gde smo] [http://soler.net.cn/data/takizawa-bakin.htm takizawa, bakin] [http://xionny.cn/topic/infradito-di/ infradito di cuoio] [http://soler.net.cn/data/kiss-gb.htm kiss gb 40] [http://wedner.info/content/view/terra-con.htm terra con] [http://xionny.cn/topic/shrapnel/ shrapnel] [http://soler.net.cn/data/orecchino-uomo.htm orecchino uomo] [http://primonona.info/content/view/macchine-da/ macchine da caffe professionali] [http://joperan.org/data/billy-elliot/ billy elliot film dvd] [http://klohy.info/img/styles/i-m.htm i m good] [http://wedner.info/content/view/pass-the.htm pass the toilet paper] [http://primonona.info/content/view/pantarei/ pantarei] [http://budget7i.info/lib/lonely-regi/ lonely regi] [http://wedner.info/content/view/fratelli-marx.htm fratelli marx] [http://wedner.info/content/view/ford-fiesta.htm ford fiesta usato] [http://primonona.info/content/view/acer-point/ acer point] [http://polex.com.cn/resources/articles/pc-far.htm pc far cry] [http://polex.com.cn/resources/articles/prov-ce.htm prov ce] [http://klohy.info/img/styles/www-ismaa.htm www ismaa it] [http://budget7i.info/lib/tps-key/ tps key multivision] [http://klohy.info/img/styles/roma-bordeaux.htm roma bordeaux biglietti aerei] [http://budget7i.info/lib/foto-di/ foto di pokem advanced] [http://funkall.us/images/small/cittadinanza/ cittadinanza] [http://primonona.info/content/view/giochi-yeti/ giochi yeti] [http://polex.com.cn/resources/articles/matrix.htm matrix 2] [http://primonona.info/content/view/gallerie-foto/ gallerie foto transessuali gratis] [http://primonona.info/content/view/tv-lcd/ tv lcd 32 pollici hdmi] [http://svike.info/view/new/termometro-a.htm termometro a infrarossi] [http://budget7i.info/lib/samsung-mb/ samsung 997mb 19] [http://joperan.org/data/sony-trv/ sony trv 270] [http://funkall.us/images/small/a-case/ a case of a crab] [http://xionny.cn/topic/ufficio-lanciano/ ufficio lanciano] [http://soler.net.cn/data/bergamo-istruzione.htm bergamo istruzione] [http://wedner.info/content/view/dsch-sony.htm dsch1 sony] [http://funkall.us/images/small/dajd/ dajd] [http://funkall.us/images/small/akcion/ akcion] [http://funkall.us/images/small/passat/ passat 2004] [http://wedner.info/content/view/ati-radeon.htm ati radeon 9200se] [http://veggis.org.cn/resources/articles/matx-schede.htm matx schede madri] [http://veggis.org.cn/resources/articles/olmo-.htm olmo 6 friends] [http://primonona.info/content/view/www-alitalia/ www alitalia com] [http://sneck.info/data/i-of/ i of the enemy in prova] [http://funkall.us/images/small/holding-out/ holding out hero] [http://svike.info/view/new/kodak-sd.htm kodak sd card] [http://primonona.info/content/view/d/ d] [http://klohy.info/img/styles/passegini-e.htm passegini e carrozzine] [http://manoke.cn/topic/pentium-/ pentium 4 3ghz] [http://klohy.info/img/styles/citroen-c.htm citroen c5 hdi] [http://veggis.org.cn/resources/articles/hit-mania.htm hit mania dance champion 2004 copertina cd] [http://budget7i.info/lib/l-acer/ l200 acer] [http://joperan.org/data/notebook-schede/ notebook schede acquisizione e tv] {{task}}
{{task}}
This task is about [[numeric arrays]]. For '''hashes''' or '''associative arrays''', please see [[Creating an Associative Array]].
This task is about [[numeric arrays]]. For '''hashes''' or '''associative arrays''', please see [[Creating an Associative Array]].



Revision as of 19:59, 28 August 2007

cavalletta cuffia clip racconti incesto famiglia microsoft windows xp media formato a2 stampanti oy asiye moon gioco piscina last minute extra convenienti per agosto ink film telecom leonardo drinn thomson dm 182 bear man euro 204 samsung hdd dalmata photos de chien digi cam apple ipod mini saint-riquier vignette sexy batteria siemens 700 mah crociera po devil may cry 2 ruben blades y willie colon hard drive case sony stampante a sublimazione bambola club pornostar lcd rz20la90 vacanze nel mondo ghisellini milena lavatrici classe a efficacia lavaggio central lancashire vino giordano processore amd schede madri un po di storia dei beatles luccio dalla canon mini dv sedere ragazza dj sesso genova battag tehri-garhwal albor srl usb pc800 grouper porno amatoriali o thou that tellest good tidings to zion invia mms devoto oli dizionario lingua italiana microsoft xp pro ita oem residence in italia tv al plasma e lcd philips lettore mp3 panasonic tavolo pranzo spalla atleta tomtom maps of western europe les deux alpes bred easy motherboard micro atx cimat lcd portatile dvd nostalgia di un piccolo grande amore toshiba 740 lcd 37 pony pizzerie firenze miramare di rimini mango visto cosi tavolo cornilleau hatteria televisori con lettore dvd digilander nike total 90 codici wafer seca1 indottrinamento vecchia russia la faccia dell ignoranza drag x850xt agp straight shooting www pattayalivecam com digiland libero singol donne claudio abbado. brahms, violin concert. dvorak, symphony no. 9, from new world teenme com poppin dem thangs elisa cd musicali camping jesolo bernhardi, august ferdinand fanghi di guam negozi scout brescia hot chocolate 14 greatest hits mysinka lacrime di pioggia di venditti pascali pino libri notre dame cocciante logos 584 amicizia tema giochi con palline old matura richard ashcroft lonely soul cartoline romantiche quotazioni fondi investimento gogli com da tavolo orologi the smashing pumkins hp dat 12 24 jacksonville hotel indesit silver r24s star wars lego sexxxys my heard will go on proliant dl360 ragazza tettona chat per adulti panini spa smash mouth u perlman inni sardi cura acne lombra sul tetto creme cellulite geoff crammonds grand prix 4 video hard temrjuk hentai puzle sistema solar traduzione latino nepote sister act moto guzzi v11 sport kodak easyshare dock dvd verbatim datalife plus azo billie joe fica rasata sborrata hora barbie sfilate lampada per giardino nino d angelo senza giacca e cravata mp3 amphisbaena www unilibro it sony dcr dvd 7e zion y lenox track 16 vacanza mare rimini tally 9025 account splitting per dark age of camelot joyce kelvin irish lottery altri tempi km0 bmw 120d auto km 0 la mano lunga del padrino neverne bebe gde smo takizawa, bakin infradito di cuoio kiss gb 40 terra con shrapnel orecchino uomo macchine da caffe professionali billy elliot film dvd i m good pass the toilet paper pantarei lonely regi fratelli marx ford fiesta usato acer point pc far cry prov ce www ismaa it tps key multivision roma bordeaux biglietti aerei foto di pokem advanced cittadinanza giochi yeti matrix 2 gallerie foto transessuali gratis tv lcd 32 pollici hdmi termometro a infrarossi samsung 997mb 19 sony trv 270 a case of a crab ufficio lanciano bergamo istruzione dsch1 sony dajd akcion passat 2004 ati radeon 9200se matx schede madri olmo 6 friends www alitalia com i of the enemy in prova holding out hero kodak sd card d passegini e carrozzine pentium 4 3ghz citroen c5 hdi hit mania dance champion 2004 copertina cd l200 acer notebook schede acquisizione e tv

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

This task is about numeric arrays. For hashes or associative arrays, please see Creating an Associative Array.

In this task, the goal is to create an array. Mention if the array base begins at a number other than zero.

ActionScript

//  ActionScript arrays are zero-based
// 
//  creates an empty array
var arr1:Array = new Array();
//  creates an array with 3 numerical values
var arr2:Array = new Array(1,2,3);
// 
// or just use the shorthand
var u:Array = [];
var v:Array = [1,2,3];

Ada

Compiler: GCC 4.1.2

Ada array indices may begin at any value, not just 0 or 1

type Arr is array (Integer range <>) of Integer;
Uninitialized : Arr (1 .. 10);
Initialized_1 : Arr (1 .. 20) := (others => 1);
Initialized_2 : Arr := (1 .. 30 => 2);
Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
Centered      : Arr (-50..50) := (0 => 1, Others => 0);

Ada arrays may be indexed by enumerated types, which are discrete non-numeric types

type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
type Activities is (Work, Fish);
type Daily_Activities is array(Days) of Activities;
This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

AppleScript

AppleScript supports "arrays" as "lists," and they are not limited by a single type.

set array1 to {}
set array2 to {1, 2, 3, 4, "hello", "world"}

BASIC

Interpeter: QuickBasic 4.5, PB 7.1

REM Force index to start at 1..n
OPTION BASE 1
REM Force index to start at 0..n
OPTION BASE 0
REM Specify that the array is dynamic and not static
'$DYNAMIC
DIM SHARED myArray(-10 TO 10, 10 TO 30) AS STRING
REDIM SHARED myArray(20, 20) AS STRING
myArray(1,1) = "Item1"
myArray(1,2) = "Item2"

C

Compiler: GCC, MSVC, BCC, Watcom

Libraries: Standard Dynamic

#include <stdlib.h> /* for malloc */
#include <string.h> /* for memset */
int n = 10 * sizeof(int);
int *myArray = (int*)malloc(n);
if(myArray != NULL)
{
  memset(myArray, 0, n);
  myArray[0] = 1;
  myArray[1] = 2;
  free(myArray);
  myArray = NULL;
}

Static

 int myArray2[10] = { 1, 2, 0}; /* 3..9 := 0 */

C

Compiler: GCC, Visual C , BCC, Watcom


Using dynamically-allocated memory:

 const int n = 10;
 int* myArray = new int[n];
 if(myArray != NULL)
 {
   myArray[0] = 1;
   myArray[1] = 2;
   delete[] myArray;
   myArray = NULL;
 }

Using fixed memory:

 int myArray2[10] = { 1, 2, 0}; /* 3..9 := 0 */

Libraries: STL

 // STL
 std::vector<int> myArray3(10);
 myArray3.push_back(1);
 myArray3.push_back(2);

Libraries: Qt

 // Qt
 QVector<int> myArray4(10);
 myArray4.push_back(1);
 myArray4.push_back(2);

Libraries: Microsoft Foundation Classes

 // MFC
 CArray<int,int> myArray5(10);
 myArray5.Add(1);
 myArray5.Add(2);

C#

Example of array of 10 int types:

 int[] numbers = new int[10];

Example of array of 3 string types:

 string[] words = { "these", "are", "arrays" };

You can also declare the size of the array and initialize the values at the same time:

 int[] more_numbers = new int[3]{ 21, 14 ,63 };


For Multi-Deminsional arrays you declare them the same except for a comma in the type declaration.

The following creates a 3x2 int matrix

 int[,] number_matrix = new int[3,2];

As with the previous examples you can also initialize the values of the array, the only difference being each row in the matrix must be enclosed in its own braces.

 string[,] string_matrix = { {"I","swam"}, {"in","the"}, {"freezing","water"} };

or

 string[,] funny_matrix = new string[2,2]{ {"clowns", "are"} , {"not", "funny"} };

Clean

Array denotations are overloaded in Clean, therefore we explicitly specify the types. There are lazy, strict, and unboxed array.

Lazy array

Create a lazy array of strings using an array denotation.

array :: {String}
array = {"Hello", "World"}

Create a lazy array of floating point values by sharing a single element.

array :: {Real}
array = createArray 10 3.1415

Create a lazy array of integers using an array (and also a list) comprehension.

array :: {Int}
array = {x \\ x <- [1 .. 10]}

Strict array

Create a strict array of integers.

array :: {!Int}
array = {x \\ x <- [1 .. 10]}

Unboxed array

Create an unboxed array of characters, also known as String.

array :: {#Char}
array = {x \\ x <- ['a' .. 'z']}

ColdFusion

Creates a one-dimensional Array

<cfset arr1 = ArrayNew(1)>

Creates a two-dimensional Array in CFScript

<cfscript>
  arr2 = ArrayNew(2);
</cfscript>

ColdFusion Arrays are NOT zero-based, they begin at index 1

Common Lisp

Creates a one-dimensional array of length 10.

(make-array 10)

Creates a two-dimensional array with dimensions 10x20.

(make-array '(10 20))

make-array may be called with a number of optional arguments.

(make-array 4 :element-type 'fixnum :initial-contents '(1 2 3 4) :adjustable t)

D

Compiler: DMD,GDC

// dynamic array
int[] numbers = new int[5];

// static array
int[5] = [0,1,2,3,4];

Forth

Forth has a variety of ways to allocate arrays of data, though it has no built-in array handling words, favoring pointer manipulation.

Static array of 200 cells, uninitialized:

create MyArray 200 cells allot
here MyArray - cell / constant MyArraySize

Static array containing the numbers 1 to 5

create MyArray   1 , 2 , 3 , 4 , 5 ,
here MyArray - cell / constant MyArraySize

Dynamic array allocation:

0 value MyArray
200 cells allocate throw to MyArray

Dynamic array free:

MyArray free throw
0 to MyArray

Fortran

Default case:

      integer a(10)

this will have ten elements. Counting starts at 1. If a zero-based array is needed, declare like this:

      integer a(0:9)

this mechanism can be extended to any numerical indices, and allowed number of dimensions (and of course to other data types than integers). For example

      real*8 (25:29,12)

will be an two-dimensional, 5x12-array of 8-byte floats, where the first dimension can be addressed numerically as 25, 26, 27, 28 or 29 (and the second dimension as 1 .. 12).


IDL

IDL doesn't really distinguish between scalars and arrays - the same operations that can create the one can usually create the other as well.

 a = 3
 help,a
 A               INT       =        3
 print,a^2
      9
 a = [3,5,8,7]
 help,a
 A               INT       = Array[4]
 print,a^2
      9      25      64      49

Java

For example for an array of 10 int values:

 int[] intArray = new int[10];

Creating an array of Strings:

 String[] s = {"hello" , "World" };

JavaScript

 var myArray = new Array();
 var myArray2 = new Array("Item1","Item2");
 var myArray3 = ["Item1", "Item2"];

MAXScript

Interpreter: 3D Studio Max 8

 myArray = #()
 myArray2 = #("Item1", "Item2")

mIRC Scripting Language

Interpeter: mIRC Script Editor Libraries: mArray Snippet

alias creatmearray { .echo -a $array_create(MyArray, 5, 10) }

OCaml

Using an array literal:

 let array = [| 1; 2; 3; 4; 5 |];;

To create an array of five elements with the value 0:

 let num_items = 5 and initial_value = 0;;
 let array = Array.make num_items initial_value

To create an array with contents defined by passing each index to a callback (in this example, the array is set to the squares of the numbers 0 through 4):

 let callback index = index * index;;
 let array = Array.init 5 callback


Perl

Interpreter: Perl 5

my @empty;
my @empty_too = ();
my @populated   = ('This', 'That', 'And', 'The', 'Other');
print $populated[2];
# And

my $aref = ['This', 'That', 'And', 'The', 'Other'];
print aref->[2];
# And
# having to quote like that really sucks, and that's why we got syntactic sugar
my @wakey_wakey = qw(coffee sugar cream);

push @wakey_wakey, 'spoon';
# add spoon to right-hand side
my $cutlery = pop @wakey_wakey;
# remove spoon

unshift @wakey_wakey, 'cup';
# add cup to left-hand side
my $container = shift @wakey_wakey;
# remove cup
my @multi_dimensional = (
    [0, 1, 2, 3],
    [qw(a b c d e f g)],
    [qw(! $ %

Toka

Toka allows creation of an array using is-array. Access to the elements is done using get-element, put-element, get-char-element, and put-char-element functions. You can not initialize the values automatically using the core array functions.

 100 cells is-array foo
 100 chars is-array bar