Creating an Array: Difference between revisions

Blanked page since people can't / don't read
mNo edit summary
(Blanked page since people can't / don't read)
 
(185 intermediate revisions by 50 users not shown)
Line 1:
{{DeprecatedTask}}
[http://ustall.org/web/siena-.htm siena 19 atc] [http://amohseni.info/img/styles/myst-iv/ myst iv in un filmato] [http://saibso.org/bacilos.htm bacilos] [http://nobinters.org/annuncio-affitti.htm annuncio affitti ferrara] [http://ustall.org/web/testo-on.htm testo on my knees] [http://davte.info/library/html/la-rush.htm la rush in foto e video] [http://psisemiya.com/images/small/isoleeolie/ isoleeolie] [http://nobinters.org/aix-en.htm aix en provence pierre e t vacance] [http://psisemiya.com/images/small/keira-knightly/ keira knightly naked] [http://bloprofeldi.info/lib/heuring.htm heuring] [http://chaba.info/te-comere/ te comere a besos] [http://psisemiya.com/images/small/breed/ breed] [http://helmed.info/topic/vacanza-puglia/ vacanza puglia residence] [http://chaba.info/mns-messenger/ mns messenger] [http://ustall.org/web/hety.htm hety] [http://bloprofeldi.info/lib/love-is.htm love is blue marty robbins] [http://helmed.info/topic/nobile/ nobile] [http://chaba.info/ef-mm/ ef 600mm] [http://davte.info/library/html/kazem.htm kazem] [http://helmed.info/topic/diminuiscono-le/ diminuiscono le vendite hardware in usa] [http://psisemiya.com/images/small/air-classic/ air classic bw] [http://davte.info/library/html/black.htm black2] [http://ustall.org/web/gps-nokia.htm gps nokia 9300] [http://saibso.org/stampante-a.htm stampante a3 ethernet colori] [http://chaba.info/intimo-dolce/ intimo dolce e gabbana uomo] [http://helmed.info/topic/ricevitori-satellitari/ ricevitori satellitari 12v] [http://chaba.info/juve-schifo/ juve schifo] [http://ustall.org/web/hotel-mediterraneo.htm hotel mediterraneo] [http://ashythro.info/library/html/the-sheltering/ the sheltering sky] [http://davte.info/library/html/epson-s.htm epson s050190] [http://chaba.info/canzoni-napoletana/ canzoni napoletana] [http://davte.info/library/html/nvidia-fx.htm nvidia fx330] [http://davte.info/library/html/pellegrini-spa.htm pellegrini spa] [http://ustall.org/web/xerox-cx.htm xerox 480cx] [http://bloprofeldi.info/lib/little-wings.htm little wings] [http://helmed.info/topic/batteria-ericsson/ batteria ericsson a1018s] [http://chaba.info/lcd-/ lcd 19 12ms] [http://davte.info/library/html/more-than.htm more than world] [http://helmed.info/topic/sandri/ sandri] [http://saibso.org/vestiti-di.htm vestiti di alessandra] [http://psisemiya.com/images/small/disturbed-forsaken/ disturbed forsaken] [http://amohseni.info/img/styles/serena-brande/ serena brande fratello] [http://psisemiya.com/images/small/denel/ denel] [http://chaba.info/blowjobs/ blowjobs] [http://ashythro.info/library/html/dvd-recorder/ dvd recorder vcr sharp] [http://saibso.org/macchina-fotografica.htm macchina fotografica on line] [http://nobinters.org/paint.htm paint] [http://nobinters.org/memoria-fotocamera.htm memoria fotocamera olympus] [http://saibso.org/www-frau.htm www frau it] [http://saibso.org/doslocos.htm doslocos] [http://saibso.org/pensiero-socialista.htm pensiero socialista comunista] [http://davte.info/library/html/rino-gaetano.htm rino gaetano mid] [http://saibso.org/pinna-da.htm pinna da nuoto] [http://davte.info/library/html/auto-noleggio.htm auto noleggio besate] [http://ustall.org/web/progettazione-macchina.htm progettazione macchina] [http://chaba.info/photostudio/ photostudio] [http://amohseni.info/img/styles/titan/ titan] [http://kinunia.cn/sassabanek.htm sassabanek] [http://kinunia.cn/clip-art.htm clip art di matrimonio] [http://amohseni.info/img/styles/la-rush/ l.a. rush] [http://bloprofeldi.info/lib/calzature-armani.htm calzature armani] [http://kinunia.cn/prada-abiti.htm prada abiti uomo] [http://ustall.org/web/copertina-cd.htm copertina cd dragostea haiducii] [http://davte.info/library/html/salute-fisica.htm salute fisica] [http://ustall.org/web/srilanka.htm srilanka] [http://chaba.info/collegio-sindacale/ collegio sindacale nella corporate] [http://davte.info/library/html/bridget-jones.htm bridget jones 2] [http://saibso.org/pian-vigne.htm pian vigne] [http://bloprofeldi.info/lib/codici-di.htm codici di acceso tps] [http://ustall.org/web/mapa-de.htm mapa de espana] [http://kinunia.cn/www-cerbone.htm www cerbone moto it] [http://amohseni.info/img/styles/esame-avvocato/ esame avvocato 2003 messina] [http://ashythro.info/library/html/marianna-jurcova/ marianna jurcova] [http://bloprofeldi.info/lib/oakley-monster.htm oakley monster dog] [http://ustall.org/web/dsc-h.htm dsc h1 sony] [http://davte.info/library/html/toshiba-satellite.htm toshiba satellite 760] [http://chaba.info/jvc-car/ jvc car audio] [http://psisemiya.com/images/small/guta-nicolae/ guta nicolae] [http://davte.info/library/html/atomik-kitten.htm atomik kitten] [http://davte.info/library/html/cartina-geografica.htm cartina geografica francia] [http://helmed.info/topic/cartoline-di/ cartoline di napoli] [http://nobinters.org/saintmichel.htm saint-michel] [http://psisemiya.com/images/small/infineon/ infineon 512] [http://ustall.org/web/puma-uomo.htm puma uomo blu] [http://bloprofeldi.info/lib/no-sikiriki.htm no sikiriki] [http://amohseni.info/img/styles/radeon-x/ radeon x800 pro 256 mb] [http://amohseni.info/img/styles/miss-nude/ miss nude] [http://psisemiya.com/images/small/toshiba-wlp/ toshiba 37wl56p] [http://ashythro.info/library/html/mai-sola/ mai sola] [http://amohseni.info/img/styles/liviu/ liviu] [http://saibso.org/copay-secondo.htm copay secondo] [http://kinunia.cn/stay-tommy.htm stay tommy vee] [http://bloprofeldi.info/lib/londra-di.htm londra di notte] [http://psisemiya.com/images/small/left-outsdie/ left outsdie alone] [http://helmed.info/topic/uruguaiana/ uruguaiana] [http://saibso.org/positano-alberghi.htm positano alberghi e hotel] [http://chaba.info/peugeot/ peugeot 106 1.1] [http://psisemiya.com/images/small/babilonia/ babilonia] [http://helmed.info/topic/attrezzatura-giardinaggio/ attrezzatura giardinaggio] [http://ustall.org/web/embalaje.htm embalaje] [http://psisemiya.com/images/small/toshiba-notebook/ toshiba notebook] [http://saibso.org/chingling.htm ching-ling] [http://ustall.org/web/porcate-assolute.htm porcate assolute] [http://amohseni.info/img/styles/tv-color/ tv color 20 pollici] [http://helmed.info/topic/il-cervello/ il cervello] [http://ashythro.info/library/html/veicoli-ed/ veicoli ed attrezzature] [http://bloprofeldi.info/lib/all-in.htm all in one computer] [http://amohseni.info/img/styles/dialoghi-in/ dialoghi in italiano del musical grease] [http://amohseni.info/img/styles/philips-sensotec/ philips sensotec] [http://kinunia.cn/palma-di.htm palma di montechiaro] [http://bloprofeldi.info/lib/dinitro.htm dinitro-] [http://davte.info/library/html/giochi-online.htm giochi online azione] [http://kinunia.cn/galitsin.htm galitsin] [http://chaba.info/bandiera-inglese/ bandiera inglese] [http://helmed.info/topic/toshiba-mx/ toshiba m40x - 269] [http://bloprofeldi.info/lib/canon-efs.htm canon ef-s 55mm] [http://davte.info/library/html/dvd-verbatim.htm dvd verbatim azo] [http://nobinters.org/dono-damore.htm dono damore] [http://amohseni.info/img/styles/puglia-case/ puglia case vacanza] [http://bloprofeldi.info/lib/moda-pelle.htm moda pelle] [http://kinunia.cn/frigor-ariston.htm frigor ariston] [http://saibso.org/new-beetle.htm new beetle noleggio] [http://psisemiya.com/images/small/la-vita/ la vita provvisoria] [http://chaba.info/piu-che/ piu che puoi] [http://kinunia.cn/luomo-del.htm luomo del treno] [http://ashythro.info/library/html/videocamera-/ videocamera 3 ccd] [http://amohseni.info/img/styles/light-blue/ light blue dolce e gabbana] [http://helmed.info/topic/si-e/ si e llave tu] [http://helmed.info/topic/solo-sesso/ solo sesso gratis] [http://kinunia.cn/sophia-bush.htm sophia bush] [http://nobinters.org/legatoria-pc.htm legatoria pc] [http://bloprofeldi.info/lib/sit.htm sit] [http://psisemiya.com/images/small/alps-chieti/ alps chieti] [http://chaba.info/momentus/ momentus 7200] [http://davte.info/library/html/asus-my.htm asus my- pal a620] [http://chaba.info/old-mom/ old mom] [http://chaba.info/kenya-mombasa/ kenya mombasa voli] [http://amohseni.info/img/styles/oralb-professional/ oral-b professional care] [http://chaba.info/hp-fotocamere/ hp fotocamere digitali] [http://amohseni.info/img/styles/acer-travelmate/ acer travelmate 360] [http://chaba.info/azienda-agraria/ azienda agraria] [http://davte.info/library/html/piedi-con.htm piedi con calze video] [http://helmed.info/topic/benasi-satisfaction/ benasi satisfaction] [http://saibso.org/muvo-tx.htm muvo tx fm da 512 mb] [http://helmed.info/topic/hotel-costa/ hotel costa azzurra] [http://helmed.info/topic/you-spin/ you spin me right round baby] [http://chaba.info/dc-enhancer/ dc enhancer] [http://ustall.org/web/www-lyco.htm www lyco com] [http://kinunia.cn/phil-ochs.htm phil ochs] [http://amohseni.info/img/styles/putas-negras/ putas negras] [http://chaba.info/el-cangri/ el cangri] [http://bloprofeldi.info/lib/dior-addict.htm dior addict 2] [http://ustall.org/web/oahu-hotel.htm oahu hotel] [http://psisemiya.com/images/small/laser-print/ laser print 2000 srl] [http://ustall.org/web/vasco-rossi.htm vasco rossi tab] [http://amohseni.info/img/styles/hotel-alexander/ hotel alexander] [http://kinunia.cn/golden-bowl.htm golden bowl, the-] [http://nobinters.org/home-theater.htm home theater wireless] [http://saibso.org/versamento-conduttore.htm versamento conduttore] [http://ustall.org/web/mi-vorresti.htm mi vorresti] [http://chaba.info/star-trek/ star trek voyager. stagione 5] [http://saibso.org/ricette-prova.htm ricette prova del cuoco] [http://ustall.org/web/torna.htm torna] [http://amohseni.info/img/styles/che/ che] [http://helmed.info/topic/gena-lee/ gena lee nolin video hard] [http://kinunia.cn/nike.htm nike 2004-2005] [http://ashythro.info/library/html/coppie-nere/ coppie nere] [http://saibso.org/discoteca-j.htm discoteca j] [http://davte.info/library/html/testo-canzone.htm testo canzone aemon] [http://davte.info/library/html/mariadefilippi.htm mariadefilippi] [http://amohseni.info/img/styles/nadia-comaneci/ nadia comaneci] [http://psisemiya.com/images/small/primavera-primavera/ primavera primavera] [http://bloprofeldi.info/lib/senza-domani.htm senza domani] [http://bloprofeldi.info/lib/russell-crowe.htm russell crowe desnudo] [http://amohseni.info/img/styles/stanlio-e/ stanlio e onlio] [http://kinunia.cn/windows-.htm windows 2000 sp4] [http://bloprofeldi.info/lib/terra-di.htm terra di ribellione] [http://amohseni.info/img/styles/it-s/ it s gonna be me] [http://saibso.org/cavo-ottico.htm cavo ottico 3 5] [http://chaba.info/bohr/ bohr] [http://kinunia.cn/veleno-toto.htm veleno toto] [http://bloprofeldi.info/lib/masterizzatori-firewire.htm masterizzatori firewire] [http://ashythro.info/library/html/forza-venite/ forza venite gente musicol] [http://saibso.org/monlight-shadow.htm monlight shadow] [http://helmed.info/topic/escape-muse/ escape muse] [http://psisemiya.com/images/small/testi-gianni/ testi gianni morandi canzone solo chi si] [http://helmed.info/topic/singolo-dotato/ singolo dotato] [http://helmed.info/topic/chicco-trio/ chicco trio 2002] [http://ustall.org/web/parole-chanson.htm parole chanson] [http://chaba.info/vendita-informatica/ vendita informatica] [http://davte.info/library/html/eva-express.htm eva express] [http://davte.info/library/html/digital.htm digital 5500] [http://davte.info/library/html/itrigue.htm i-trigue 2200] [http://kinunia.cn/digital-pen.htm digital pen nokia] [http://davte.info/library/html/driver-stampante.htm driver stampante hp download] [http://helmed.info/topic/znojmo/ znojmo] [http://kinunia.cn/peternorth.htm peternorth] [http://helmed.info/topic/accessori-cavi/ accessori cavi coassiale] [http://ustall.org/web/la-luna.htm la luna sul vetro] [http://ustall.org/web/www-laurax.htm www laurax com] {{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.
(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 'fixnum :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];
 
==[[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
10,327

edits