Creating an Array: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
(Blanked page since people can't / don't read)
 
(157 intermediate revisions by 50 users not shown)
Line 1: Line 1:
{{DeprecatedTask}}
[http://jite.netfirms.com/new/don-gnocchi/ don gnocchi (2 dvd)] [http://badanglican.cn/content/view/tauro/ tauro] [http://cacogdil.angelfire.com/web/aculaser-c.htm aculaser c1100 epson stampanti] [http://myasa-kusochek.netfirms.com/lib/bloom-harold/ bloom harold] [http://syashwor.angelfire.com/directory/quiero-ser.htm quiero ser] [http://whrichey.angelfire.com/content/amanti-di/ amanti di toledo gli] [http://badanglican.cn/content/view/babasonicos-infame/ babasonicos infame] [http://badanglican.cn/content/view/seggiolino-l/ seggiolino l rossi] [http://webancks.angelfire.com/lycos-motore.htm lycos motore di ricerca] [http://lubrevel.angelfire.com/new/gangsters-paradise/ gangsters paradise] [http://cacogdil.angelfire.com/web/velodyne-cht.htm velodyne cht 10] [http://hungry87.netfirms.com/styles/giochi-di/ giochi di bar] [http://eiwiggin.angelfire.com/small/speedupmypc/ speedupmypc 117] [http://badanglican.cn/content/view/moana-e/ moana e morta] [http://michelletrach.netfirms.com/gael-garcia.htm gael garcia bernal] [http://lubrevel.angelfire.com/new/bmw-/ bmw 320 d tdi 2001] [http://themarjorie.netfirms.com/coi-piedi.htm coi piedi sul palco] [http://xrikuxsorax103.netfirms.com/britney-prerogative/ britney prerogative] [http://cacogdil.angelfire.com/web/l-inverno.htm l inverno e passato] [http://mybabydontsleep.netfirms.com/text/hot-bird.htm hot bird] [http://prhaffen.angelfire.com/library/lynnsha.htm lynnsha] [http://badanglican.cn/content/view/hard-boiled/ hard boiled] [http://knbrenne.angelfire.com/data/nokia-.htm nokia 6600 tomtom mobile] [http://badanglican.cn/content/view/www-biagio/ www biagio antonacci it] [http://kimccanl.angelfire.com/decapitaciones-octubre.htm decapitaciones octubre] [http://grhenric.angelfire.com/html/jojo-mp/ jojo mp3] [http://badanglican.cn/content/view/turn-off/ turn off] [http://badanglican.cn/content/view/selleria/ selleria] [http://badanglican.cn/content/view/mtrix/ mtrix] [http://eiwiggin.angelfire.com/small/io-so/ io so chi ha ucciso] [http://kehampsh.angelfire.com/view/porristas-com/ porristas com] [http://myasa-kusochek.netfirms.com/lib/dimage/ dimage 400] [http://zaweaver.angelfire.com/html/junior-jack/ junior jack] [http://badanglican.cn/content/view/martin-short/ martin short] [http://mastrong.angelfire.com/articles/reti-letto.htm reti letto] [http://azagtot.netfirms.com/blog/centro-impiego.htm centro impiego modena] [http://diferente.netfirms.com/view/calcio-notizia.htm calcio notizia] [http://michelletrach.netfirms.com/ht-jobs.htm h0t jobs] [http://knbrenne.angelfire.com/data/elliott-gould.htm elliott gould] [http://rospear.angelfire.com/styles/larranaga/ larranaga] [http://hungry87.netfirms.com/styles/decapitazione-soldato/ decapitazione soldato iraq video] [http://badanglican.cn/content/view/programmazione-net/ programmazione net] [http://eiwiggin.angelfire.com/small/ww-ovni/ ww ovni tv] [http://knbrenne.angelfire.com/data/minox-fotocamere.htm minox fotocamere] [http://hungry87.netfirms.com/styles/dvd-hd/ dvd hd recorder divx] [http://rohutsonik.angelfire.com/blog/wedding-of.htm wedding of sheva] [http://kimccanl.angelfire.com/www-gogle.htm www gogle com] [http://lubrevel.angelfire.com/new/hengher/ hengher] [http://badanglican.cn/content/view/giuseppe-castiglia/ giuseppe castiglia] [http://diferente.netfirms.com/view/sanford-e.htm sanford e son] [http://lubrevel.angelfire.com/new/sweety-lullaby/ sweety lullaby] [http://rospear.angelfire.com/styles/iggy-pop/ iggy pop live san fran 1981] [http://mastrong.angelfire.com/articles/handyman.htm handyman] [http://cacogdil.angelfire.com/web/renault-concessionaria.htm renault concessionaria rimini] [http://hungry87.netfirms.com/styles/lettore-mp/ lettore mp3 nwhd5] [http://badanglican.cn/content/view/philips/ philips 515] [http://whrichey.angelfire.com/content/mercedes-e/ mercedes e 250 d] [http://myasa-kusochek.netfirms.com/lib/besame-mucho/ besame mucho] [http://mybabydontsleep.netfirms.com/text/incontri-erotici.htm incontri erotici] [http://badanglican.cn/content/view/rotolando-respirando/ rotolando respirando] [http://badanglican.cn/content/view/ponernos-de/ ponernos de acuerdo] [http://grhenric.angelfire.com/html/porno-in/ porno in internet] [http://mybabydontsleep.netfirms.com/text/giana-nanini.htm giana nanini] [http://mastrong.angelfire.com/articles/pantaloni-uomo.htm pantaloni uomo raso] [http://badanglican.cn/content/view/eizo-s/ eizo s1910] [http://badanglican.cn/content/view/mito-origine/ mito origine] [http://badanglican.cn/content/view/danzel-the/ danzel the name of the jam] [http://xrikuxsorax103.netfirms.com/traduzioni-simultanee/ traduzioni simultanee] [http://piratical-map.netfirms.com/lib/elettrostimolatori-professionali/ elettrostimolatori professionali globus] [http://lubrevel.angelfire.com/new/skye-sweetnam/ skye sweetnam foto] [http://badanglican.cn/content/view/www-cartu/ www cartu] [http://badanglican.cn/content/view/cellular-automata/ cellular automata viewer] [http://michelletrach.netfirms.com/rosso-nel.htm rosso nel buio] [http://myasa-kusochek.netfirms.com/lib/si-tratta/ si tratta dell amore di edordo bennato] [http://domiver.angelfire.com/data/volare-it.htm volare it] [http://diferente.netfirms.com/view/www-istr.htm www istr it] [http://hilyndel.angelfire.com/lib/cavalli-puro.htm cavalli puro sangue egiziano] [http://mybabydontsleep.netfirms.com/text/bubblin-traduzione.htm bubblin traduzione] [http://piratical-map.netfirms.com/lib/acer-g/ acer g310] [http://merengo.netfirms.com/html/fenomeni-paranormali.htm fenomeni paranormali] [http://hilyndel.angelfire.com/lib/un-brivido.htm un brivido sulla pelle] [http://prhaffen.angelfire.com/library/canzoni-anastacia.htm canzoni anastacia] [http://merengo.netfirms.com/html/pirani.htm pirani] [http://cacogdil.angelfire.com/web/mischa-auer.htm mischa auer] [http://webancks.angelfire.com/fogli-lucidi.htm fogli lucidi] [http://merengo.netfirms.com/html/frequenze-astra.htm frequenze astra] [http://michelletrach.netfirms.com/caniche.htm caniche] [http://whrichey.angelfire.com/content/formazione-francia/ formazione francia] [http://rospear.angelfire.com/styles/passion-de/ passion de gavilanes] [http://broken-lens.netfirms.com/web/bleona/ bleona] [http://kehampsh.angelfire.com/view/mouse-cordless/ mouse cordless logitech] [http://rohutsonik.angelfire.com/blog/smartphone-qtek.htm smartphone qtek 8100] [http://xrikuxsorax103.netfirms.com/quotazione-lancia/ quotazione lancia lybra] [http://hungry87.netfirms.com/styles/automodello-con/ automodello con motore scoppio] [http://badanglican.cn/content/view/www-univision/ www univision com] [http://badanglican.cn/content/view/franchising-accessorio/ franchising accessorio] [http://knbrenne.angelfire.com/data/fujifilm-finepix.htm fujifilm finepix f410] [http://badanglican.cn/content/view/ritratto-dorian/ ritratto dorian grey] [http://badanglican.cn/content/view/villaggi-naturisti/ villaggi naturisti in europa] [http://rospear.angelfire.com/styles/hotel-mamy/ hotel mamy] [http://merengo.netfirms.com/html/cerca-voli.htm cerca voli] [http://whrichey.angelfire.com/content/entrapment-of/ entrapment of mind] [http://cacogdil.angelfire.com/web/thyratron.htm thyratron] [http://eiwiggin.angelfire.com/small/la-grande/ la grande prova] [http://hilyndel.angelfire.com/lib/zucchero-miserere.htm zucchero miserere] [http://hungry87.netfirms.com/styles/novara-massaggiatrici/ novara massaggiatrici] [http://blgottlo.angelfire.com/attrezzo-tecnogym/ attrezzo tecnogym] [http://diferente.netfirms.com/view/beautyful.htm beautyful] [http://mybabydontsleep.netfirms.com/text/bub.htm bub] [http://badanglican.cn/content/view/totti-che/ totti che sputa] [http://badanglican.cn/content/view/vernate/ vernate] [http://badanglican.cn/content/view/games-free/ games free] [http://hungry87.netfirms.com/styles/soffia-bertoli/ soffia bertoli] [http://hungry87.netfirms.com/styles/djenet/ djenet] [http://piratical-map.netfirms.com/lib/pippi-calzelunghe/ pippi calzelunghe il personaggio] [http://whrichey.angelfire.com/content/aramadillo/ aramadillo] [http://kehampsh.angelfire.com/view/modelle-erotiche/ modelle erotiche] [http://mastrong.angelfire.com/articles/anal-toy.htm anal toy] [http://badanglican.cn/content/view/confiteo/ confiteo] [http://piratical-map.netfirms.com/lib/uj/ uj] [http://zaweaver.angelfire.com/html/un-areoplano/ un areoplano a vela] [http://badanglican.cn/content/view/f-/ f 3 nikon] [http://themarjorie.netfirms.com/le-rb.htm le 26r41b] [http://badanglican.cn/content/view/collane-donna/ collane donna oro] [http://mastrong.angelfire.com/articles/ornitologia.htm ornitologia] [http://badanglican.cn/content/view/che-bambola/ che bambola] [http://rohutsonik.angelfire.com/blog/kingston-gb.htm kingston 2gb high speed compact flash] [http://piratical-map.netfirms.com/lib/hot-nude/ hot nude woman] [http://merengo.netfirms.com/html/www-recaro.htm www recaro de] [http://badanglican.cn/content/view/multipresa-/ multipresa 10 prese] [http://xrikuxsorax103.netfirms.com/modello-f/ modello f23] [http://mastrong.angelfire.com/articles/tranny-free.htm tranny free galleries] [http://xrikuxsorax103.netfirms.com/vendita-computer/ vendita computer palmare] [http://zaweaver.angelfire.com/html/la-badessa/ la badessa di castro] [http://badanglican.cn/content/view/nortek-mp/ nortek mp3 1gb] [http://badanglican.cn/content/view/westling/ westling] [http://hungry87.netfirms.com/styles/the-sims/ the sims bustin out] [http://myasa-kusochek.netfirms.com/lib/lettore-dvd/ lettore dvd portatile 8 pollici lettori] [http://badanglican.cn/content/view/deumidificatori-aria/ deumidificatori aria] [http://badanglican.cn/content/view/vdo-dayton/ vdo dayton navigatori] [http://merengo.netfirms.com/html/streuvels-stijn.htm streuvels stijn] [http://hungry87.netfirms.com/styles/lamezia-terme/ lamezia terme roma biglietti aerei] [http://cacogdil.angelfire.com/web/gerry-rafferty.htm gerry rafferty] [http://whrichey.angelfire.com/content/scarpa-merrel/ scarpa merrel] [http://hungry87.netfirms.com/styles/leave-get/ leave get out jojo] [http://themarjorie.netfirms.com/pontiac.htm pontiac] [http://badanglican.cn/content/view/lampada-b/ lampada b10] [http://rospear.angelfire.com/styles/voglio-vedere/ voglio vedere la figa di manuela arcuri] [http://myasa-kusochek.netfirms.com/lib/musica-do/ musica do filme o ultimo dos moicanos] [http://mybabydontsleep.netfirms.com/text/desnos-robert.htm desnos robert] [http://badanglican.cn/content/view/la-ragazza/ la ragazza di dublino] [http://cacogdil.angelfire.com/web/case-vacanza.htm case vacanza lecce] [http://badanglican.cn/content/view/pompini-con/ pompini con cavalli] [http://piratical-map.netfirms.com/lib/una-demo/ una demo per ufo aftermath] [http://kehampsh.angelfire.com/view/lavoro-jesi/ lavoro jesi] [http://badanglican.cn/content/view/vino-trentino/ vino trentino] [http://broken-lens.netfirms.com/web/sector/ sector] [http://blgottlo.angelfire.com/www-azzurra/ www azzurra it] [http://kehampsh.angelfire.com/view/vedi-maria/ vedi maria] [http://badanglican.cn/content/view/xerox-dn/ xerox 7300dn] [http://badanglican.cn/content/view/piu-insieme/ piu insieme] [http://grhenric.angelfire.com/html/generatore-di/ generatore di corrente 5 kw] [http://badanglican.cn/content/view/collezione-intimo/ collezione intimo autunno-inverno] [http://michelletrach.netfirms.com/cavo-dvi.htm cavo dvi 5m] [http://broken-lens.netfirms.com/web/iqmarathon/ iqmarathon] [http://lubrevel.angelfire.com/new/lcd-tv/ lcd tv 20] [http://jite.netfirms.com/new/cartier/ cartier] [http://themarjorie.netfirms.com/thief.htm thief] [http://jite.netfirms.com/new/foto-mogli/ foto mogli amatoriali] [http://jite.netfirms.com/new/touran-milano/ touran milano] [http://badanglican.cn/content/view/stampanti-hp/ stampanti hp laserjet 1015] [http://syashwor.angelfire.com/directory/amd-.htm amd 2200 sempron] [http://rospear.angelfire.com/styles/www-finemiro/ www finemiro it] [http://diferente.netfirms.com/view/distrofia.htm distrofia] [http://knbrenne.angelfire.com/data/vargues-ursula.htm vargues ursula] [http://badanglican.cn/content/view/lettore-memory/ lettore memory card pcmcia] [http://syashwor.angelfire.com/directory/quick-cash.htm quick cash] [http://badanglican.cn/content/view/samsung-gb/ samsung 200gb] [http://michelletrach.netfirms.com/sfida-alla.htm sfida alla legge] [http://piratical-map.netfirms.com/lib/soggetti-proibiti/ soggetti proibiti] [http://blgottlo.angelfire.com/filmati-colonne/ filmati colonne sonore e memory card per devil may cry 3] [http://syashwor.angelfire.com/directory/samsung-rt.htm samsung rt 34] [http://rohutsonik.angelfire.com/blog/lumen.htm lumen 4] [http://merengo.netfirms.com/html/sin-ritorna.htm sin ritorna dal passato] [http://hungry87.netfirms.com/styles/milano-santa/ milano santa cruz] [http://badanglican.cn/content/view/navi-moby/ navi moby lines] [http://whrichey.angelfire.com/content/robby-willians/ robby willians] [http://rohutsonik.angelfire.com/blog/the-sims.htm the sims 2 si apre al business] [http://themarjorie.netfirms.com/iaudio-x.htm iaudio x5 60gb] [http://kehampsh.angelfire.com/view/indiana-jones/ indiana jones in azione su playstation 2] [http://michelletrach.netfirms.com/opel-corsa.htm opel corsa 15td] [http://domiver.angelfire.com/data/lil-bow.htm lil bow wow thank you] [http://zaweaver.angelfire.com/html/ecoscandaglio-garmin/ ecoscandaglio garmin 250] [http://kehampsh.angelfire.com/view/milano-saint/ milano saint denis de la reunion] [http://badanglican.cn/content/view/lebt-denn/ lebt denn dr alte holzmichl] [http://themarjorie.netfirms.com/valerio-foglia.htm valerio foglia manzillo] [http://badanglican.cn/content/view/gioco-pesca/ gioco pesca pc] [http://jite.netfirms.com/new/gruppo-energy/ gruppo energy protector] [http://merengo.netfirms.com/html/tv-sony.htm tv sony 28] [http://blgottlo.angelfire.com/yammat/ yammat] {{task}}
'''Please do not add new code, and merge existing code to the [[Arrays]] task.'''
This task is about [[numeric arrays]]. For '''hashes''' or '''associative arrays''', please see [[Creating an Associative Array]].


This task is about numerically-indexed 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.


In this task, the goal is to create an [[array]]. Mention if the [[array base]] begins at a number other than zero.
==[[ActionScript]]==
In addition, demonstrate how to initialize an array variable with data.
[[Category: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]]==
[[Category: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]]==
[[Category: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]]==
[[Category: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]]==
[[Category: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 plus plus|C ]]==
[[Category:C plus plus]]
'''Compiler:''' [[GCC]], [[Visual C plus plus|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 sharp|C#]]==
[[Category:C sharp]]
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]]==
[[Category: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 <tt>String</tt>.
array :: {#Char}
array = {x \\ x <- ['a' .. 'z']}

==[[ColdFusion]]==
[[Category: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]]==
[[Category:Common Lisp]]
Creates a one-dimensional array of length 10. The initial contents are undefined.
(make-array 10)
Creates a two-dimensional array with dimensions 10x20.
(make-array '(10 20))
<tt>make-array</tt> may be called with a number of optional arguments.
(make-array 4 :element-type 'integer :initial-contents '(1 2 3 4) :adjustable t)

==[[D]]==
[[Category:D]]
'''Compiler:''' [[DMD]],[[GDC]]

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

==[[E]]==
[[Category:E]]

[] # immutable, empty
[1,9,17] # immutable, 3 elements
[].diverge() # mutable, empty
[].diverge(int) # mutable, integers only

==[[Forth]]==
[[Category: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]]==
[[Category: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]]==
[[Category:IDL]]

IDL doesn't really distinguish between scalars and arrays - the same operations that can create the one can <i>usually</i> 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]]==
[[Category: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]]==
[[Category:JavaScript]]
var myArray = new Array();
var myArray2 = new Array("Item1","Item2");
var myArray3 = ["Item1", "Item2"];

==[[MAXScript]]==
[[Category:MAXScript]]
'''Interpreter:''' [[3D Studio Max]] 8
myArray = #()
myArray2 = #("Item1", "Item2")

==[[mIRC Scripting Language]]==
[[Category:mIRC Scripting Language]]
'''Interpeter:''' mIRC Script Editor
'''Libraries:''' [[mArray Snippet]]
alias creatmearray { .echo -a $array_create(MyArray, 5, 10) }

==[[OCaml]]==
[[Category: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]]==
[[Category: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]]==
[[Category: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

Latest revision as of 15:07, 29 November 2019

Creating an Array was a programming task. It has been deprecated for reasons that are discussed in its talk page.

Please do not add new code, and merge existing code to the Arrays task.

This task is about numerically-indexed 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. In addition, demonstrate how to initialize an array variable with data.