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)
 
(159 intermediate revisions by 50 users not shown)
Line 1: Line 1:
{{DeprecatedTask}}
[http://kamedcal.125mb.com/preventivi-rca.htm preventivi rca] [http://bemedad.125mb.com/blog/inno-della.htm inno della marina militare italiana] [http://kuzelka111.ifrance.com/lib/renault-sc/ renault sc nic] [http://bakedsmurf.ifrance.com/description/e-c/ e c w] [http://sylverrain.ifrance.com/data/mamma-festa/ mamma festa] [http://superspounge.ifrance.com/serbocroato/ serbocroato] [http://bakedsmurf.ifrance.com/description/www-ambasciata/ www ambasciata greca it] [http://superspounge.ifrance.com/photosmart-/ photosmart 850 hp] [http://dragonzgrace.ifrance.com/description/mr-c/ mr c] [http://superspounge.ifrance.com/syncmaster-mp/ syncmaster 730mp] [http://todkonda.ifrance.com/content/offrolavoro-it/ offrolavoro it] [http://sylverrain.ifrance.com/data/camerieri/ camerieri] [http://sylverrain.ifrance.com/data/los-jedes/ los jedes] [http://sylverrain.ifrance.com/data/benasi-satisfaction/ benasi satisfaction] [http://mike12305.ifrance.com/lib/sony-fotocamera/ sony fotocamera dsc h1] [http://doloeb.125mb.com/hard-dvd.htm hard dvd recorder divx] [http://kewheatl.125mb.com/library/hp-laser.htm hp laser 1160] [http://kamedcal.125mb.com/fx.htm fx 890] [http://stbrocke.125mb.com/content/stampante-hp.htm stampante hp 1300] [http://mamerium.125mb.com/pandora-tomorrow.htm pandora tomorrow] [http://earthlygnome.ifrance.com/jakson/ jakson] [http://dragonzgrace.ifrance.com/description/zafira-elegance/ zafira elegance] [http://vanopo.ifrance.com/library/virtual-insanity/ virtual insanity] [http://doloeb.125mb.com/colegialas-peruanas.htm colegialas peruanas desnudas] [http://kewheatl.125mb.com/library/los-angeles.htm los angeles alberghi e hotel] [http://sylverrain.ifrance.com/data/photostudio/ photostudio] [http://kuzelka111.ifrance.com/lib/bagliori-di/ bagliori di guerra] [http://stbrocke.125mb.com/content/desnudo.htm desnudo] [http://prkinardan.125mb.com/styles/incontri-a.htm incontri a agrigento] [http://kuzelka111.ifrance.com/lib/sony-cybershot/ sony cybershot dsc s90] [http://earthlygnome.ifrance.com/costo-rottame/ costo rottame] [http://mike12305.ifrance.com/lib/ww-petardas/ ww petardas con] [http://mamerium.125mb.com/casse-subwoofer.htm casse subwoofer yamaha] [http://madavidan.125mb.com/text/buildings-material.htm buildings material] [http://earthlygnome.ifrance.com/a-riva/ a riva o arriva] [http://sylverrain.ifrance.com/data/diffusori-pc/ diffusori pc] [http://raneely.125mb.com/text/clona.htm clona] [http://todkonda.ifrance.com/content/cannata/ cannata] [http://kuzelka111.ifrance.com/lib/string-bikini/ string bikini] [http://bemedad.125mb.com/blog/piedi-donne.htm piedi donne] [http://mcgoley.125mb.com/articles/karla-giraldo.htm karla giraldo] [http://madavidan.125mb.com/text/fortunale.htm fortunale] [http://sylverrain.ifrance.com/data/peter-pindar/ peter pindar] [http://todkonda.ifrance.com/content/psychic/ psychic] [http://prkinardan.125mb.com/styles/gta-libertycitystories.htm gta libertycitystories] [http://mike12305.ifrance.com/lib/sweet-dreams/ sweet dreams marylin manson] [http://mcgoley.125mb.com/articles/majestic-scd.htm majestic scd 99 mp3] [http://bemedad.125mb.com/blog/pininfarina.htm pininfarina] [http://todkonda.ifrance.com/content/dvd-top/ dvd top gun] [http://kuzelka111.ifrance.com/lib/free-gp/ free 3gp porn video] [http://mamerium.125mb.com/libri-gastronomia.htm libri gastronomia] [http://stbrocke.125mb.com/content/scuola-net.htm scuola net] [http://kewheatl.125mb.com/library/toto-a.htm toto a colori] [http://raneely.125mb.com/text/lancome-o.htm lancome o] [http://mcgoley.125mb.com/articles/n-cellulari.htm n91 cellulari nokia] [http://todkonda.ifrance.com/content/mp-de/ mp3 de aventura] [http://mike12305.ifrance.com/lib/millennium-srl/ millennium srl] [http://kuzelka111.ifrance.com/lib/scheda-video/ scheda video sis] [http://todkonda.ifrance.com/content/le-avventure/ le avventure di garfield] [http://earthlygnome.ifrance.com/casta-e/ casta e pura] [http://kamedcal.125mb.com/mega-cazzi.htm mega cazzi] [http://kamedcal.125mb.com/v-cellulari.htm v55 cellulari sagem] [http://sylverrain.ifrance.com/data/banditos/ banditos] [http://dragonzgrace.ifrance.com/description/bust-a/ bust a grove] [http://stbrocke.125mb.com/content/macchina-delle.htm macchina delle bolle] [http://kuzelka111.ifrance.com/lib/utac/ utac] [http://dragonzgrace.ifrance.com/description/ordinary-world/ ordinary world] [http://mike12305.ifrance.com/lib/seno-maturo/ seno maturo] [http://bakedsmurf.ifrance.com/description/metalica/ metalica] [http://prkinardan.125mb.com/styles/alfa-romeo.htm alfa romeo 146] [http://vanopo.ifrance.com/library/muta-subacquea/ muta subacquea] [http://kuzelka111.ifrance.com/lib/coltivazione-canapa/ coltivazione canapa] [http://mcgoley.125mb.com/articles/cenario.htm cenario] [http://earthlygnome.ifrance.com/ocean-d/ ocean d290] [http://superspounge.ifrance.com/buttane/ buttane] [http://mcgoley.125mb.com/articles/gamepad-xbox.htm gamepad xbox] [http://raneely.125mb.com/text/assicurazione-vendere.htm assicurazione vendere] [http://sylverrain.ifrance.com/data/wingchun/ wingchun] [http://kewheatl.125mb.com/library/consulti-cartomanzia.htm consulti cartomanzia amore cartomante] [http://bakedsmurf.ifrance.com/description/the-loveless/ the loveless] [http://mamerium.125mb.com/mizer.htm mizer] [http://doloeb.125mb.com/miami-super.htm miami super cops] [http://bakedsmurf.ifrance.com/description/tylko-czarne/ tylko czarne oczy] [http://dragonzgrace.ifrance.com/description/lady-soul/ lady soul] [http://doloeb.125mb.com/romania-trezeste.htm romania trezeste te] [http://madavidan.125mb.com/text/beati-paoli.htm beati paoli libri] [http://kuzelka111.ifrance.com/lib/donnald-it/ donnald it] [http://prkinardan.125mb.com/styles/batterie-sony.htm batterie sony np] [http://kuzelka111.ifrance.com/lib/samsung-kit/ samsung kit toner] [http://earthlygnome.ifrance.com/box-esterno/ box esterno 3 5 usb ata] [http://sylverrain.ifrance.com/data/banbridge/ banbridge] [http://bemedad.125mb.com/blog/hp.htm hp 6620] [http://raneely.125mb.com/text/acer.htm acer 16] [http://bemedad.125mb.com/blog/hotel-arabba.htm hotel arabba] [http://bakedsmurf.ifrance.com/description/sbs/ sbs 350] [http://bemedad.125mb.com/blog/hp-color.htm hp color laserjet a3] [http://mcgoley.125mb.com/articles/finanziamento-ascoli.htm finanziamento ascoli] [http://doloeb.125mb.com/tormentoni-dell.htm tormentoni dell estate] [http://vanopo.ifrance.com/library/girls-transex/ girls transex] [http://madavidan.125mb.com/text/volere-o.htm volere o volare valentina] [http://doloeb.125mb.com/l-isola.htm l isola dei famosi 1] [http://bakedsmurf.ifrance.com/description/o-c/ o c theme] [http://raneely.125mb.com/text/pal-ntsc.htm pal ntsc] [http://bakedsmurf.ifrance.com/description/cooperative-edilizie/ cooperative edilizie torino] [http://raneely.125mb.com/text/chihuahua-bianco.htm chihuahua bianco a pelo lungo] [http://kewheatl.125mb.com/library/donne-per.htm donne per sigoli sicilia] [http://bakedsmurf.ifrance.com/description/prime-mosse/ prime mosse per blue label entertainment] [http://mike12305.ifrance.com/lib/desiderio-del/ desiderio del cuore] [http://todkonda.ifrance.com/content/dedica-una/ dedica una cancion] [http://superspounge.ifrance.com/brums/ brums] [http://dragonzgrace.ifrance.com/description/tastiera-/ tastiera 10 metri] [http://doloeb.125mb.com/il-castello.htm il castello dei morti vivi] [http://mcgoley.125mb.com/articles/epson-.htm epson 4000 rip professional] [http://kamedcal.125mb.com/lavatrice-ariston.htm lavatrice ariston avsl 109] [http://stbrocke.125mb.com/content/caiazzo.htm caiazzo] [http://superspounge.ifrance.com/brondi-cordless/ brondi cordless best] [http://mike12305.ifrance.com/lib/pimp-on/ pimp on kanye west] [http://doloeb.125mb.com/ee.htm ee] [http://kuzelka111.ifrance.com/lib/ammazza-pinguino/ ammazza pinguino] [http://bemedad.125mb.com/blog/harlan-county.htm harlan county usa] [http://mike12305.ifrance.com/lib/notebook-parallela/ notebook parallela] [http://sylverrain.ifrance.com/data/sparkle-gf/ sparkle gf6600 256mb pciexpress] [http://todkonda.ifrance.com/content/vacanza-benessere/ vacanza benessere italia] [http://madavidan.125mb.com/text/alberghi-a.htm alberghi a vasto] [http://kamedcal.125mb.com/mmm.htm mmm100] [http://todkonda.ifrance.com/content/king-arthur/ king arthur lancillotto] [http://raneely.125mb.com/text/zoom-ottico.htm zoom ottico 12x stabilizzatore] [http://kewheatl.125mb.com/library/piaggio-liberty.htm piaggio liberty 200 4t] [http://kuzelka111.ifrance.com/lib/forza-venite/ forza venite gente musicol] [http://stbrocke.125mb.com/content/secondi-canale.htm secondi canale] [http://madavidan.125mb.com/text/delfynn-delage.htm delfynn delage] [http://vanopo.ifrance.com/library/italia-puglia/ italia puglia vacanze] [http://kamedcal.125mb.com/radio-lettore.htm radio lettore mp3 20gb] [http://madavidan.125mb.com/text/www-blupanorama.htm www blupanorama] [http://earthlygnome.ifrance.com/le-r/ le 23r51 samsung] [http://earthlygnome.ifrance.com/comune-milano/ comune milano] [http://superspounge.ifrance.com/nuova-porsche/ nuova porsche 911 benzina auto nuove] [http://mamerium.125mb.com/annuncio-affitti.htm annuncio affitti trentino alto adige] [http://sylverrain.ifrance.com/data/lettore-dvd/ lettore dvd divx portatile toshiba] [http://mike12305.ifrance.com/lib/playboy-xbox/ playboy xbox] [http://superspounge.ifrance.com/grand-valley/ grand valley] [http://todkonda.ifrance.com/content/dimage-a/ dimage a2 minolta] [http://mamerium.125mb.com/perito-assicurativo.htm perito assicurativo] [http://sylverrain.ifrance.com/data/frozen-ball/ frozen ball] [http://bemedad.125mb.com/blog/www-com.htm www com] [http://doloeb.125mb.com/camping-provincia.htm camping provincia latina] [http://madavidan.125mb.com/text/ricambi-x.htm ricambi x go kart] [http://bakedsmurf.ifrance.com/description/ethernet-pci/ ethernet pci] [http://kamedcal.125mb.com/hosting-economico.htm hosting economico] [http://bemedad.125mb.com/blog/lihg.htm lihg] [http://madavidan.125mb.com/text/serbi-serbi.htm serbi serbi] [http://mamerium.125mb.com/roldan.htm roldan] [http://todkonda.ifrance.com/content/ricetta-danubio/ ricetta danubio] [http://doloeb.125mb.com/come-seminare.htm come seminare un prato inglese] [http://doloeb.125mb.com/playboy-gratis.htm playboy gratis] [http://stbrocke.125mb.com/content/villaggi-del.htm villaggi del ventaglio] [http://kewheatl.125mb.com/library/gps-garmin.htm gps garmin iii plus] [http://prkinardan.125mb.com/styles/yattaman-vol.htm yattaman vol 01] [http://sylverrain.ifrance.com/data/commisione-esami/ commisione esami di maturita] [http://todkonda.ifrance.com/content/www-negre/ www negre it] [http://todkonda.ifrance.com/content/ddr-sdram/ ddr sdram pc2100 512] [http://mamerium.125mb.com/i-flintstones.htm i flintstones i flintstones in viva rock vegas] [http://earthlygnome.ifrance.com/cruzer-braun/ cruzer braun] [http://doloeb.125mb.com/julia-robers.htm julia robers nudo integrale] [http://bakedsmurf.ifrance.com/description/dafa/ dafa] [http://prkinardan.125mb.com/styles/exel.htm exel] [http://superspounge.ifrance.com/partiro-per/ partiro per bologna] [http://dragonzgrace.ifrance.com/description/maturita-/ maturita 2004 prima prova] [http://mike12305.ifrance.com/lib/albergo-kiev/ albergo kiev] [http://sylverrain.ifrance.com/data/oops-sexy/ oops sexy ratis] [http://bakedsmurf.ifrance.com/description/live-to/ live to love you] [http://mcgoley.125mb.com/articles/r-e.htm r e m automatic for the people] [http://vanopo.ifrance.com/library/ordini-sacerdotali/ ordini sacerdotali] [http://kuzelka111.ifrance.com/lib/eu-diventa/ eu diventa piu grande] [http://vanopo.ifrance.com/library/tango-dell/ tango dell alpino] [http://mike12305.ifrance.com/lib/make-heaven/ make heaven] [http://sylverrain.ifrance.com/data/huggy-zippy/ huggy zippy] [http://sylverrain.ifrance.com/data/giochi-costruttivi/ giochi costruttivi] [http://mike12305.ifrance.com/lib/windows-home/ windows home edition] [http://bakedsmurf.ifrance.com/description/curriculm-vitae/ curriculm vitae] [http://kamedcal.125mb.com/wolf-max.htm wolf max] [http://vanopo.ifrance.com/library/la-piua/ la piua bella sei tu] [http://dragonzgrace.ifrance.com/description/versace-per/ versace per uomo] [http://mcgoley.125mb.com/articles/bluethooth-samsung.htm bluethooth samsung z500] [http://madavidan.125mb.com/text/er-pc.htm er pc] [http://dragonzgrace.ifrance.com/description/sigma/ sigma 10] [http://sylverrain.ifrance.com/data/nokia-/ nokia 9500 i] [http://madavidan.125mb.com/text/joseph-fonseca.htm joseph fonseca en vivo] [http://mamerium.125mb.com/herson.htm herson] [http://kewheatl.125mb.com/library/sally-de.htm sally de andre] [http://sylverrain.ifrance.com/data/la-nona/ la nona configurazione] [http://mamerium.125mb.com/tastiere-bluetooth.htm tastiere bluetooth] [http://madavidan.125mb.com/text/lavatrice-rex.htm lavatrice rex jetsy] [http://bemedad.125mb.com/blog/crossfire-chrysler.htm crossfire chrysler] [http://sylverrain.ifrance.com/data/il-dono/ il dono] [http://mcgoley.125mb.com/articles/close-your.htm close your eyes] [http://dragonzgrace.ifrance.com/description/logic-pro/ logic pro] [http://madavidan.125mb.com/text/espagna-scandalo.htm espagna scandalo] [http://todkonda.ifrance.com/content/www-kermesse/ www kermesse] [http://superspounge.ifrance.com/al-cinema/ al cinema febbraio 2006] {{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.