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)
 
(192 intermediate revisions by 50 users not shown)
Line 1: Line 1:
{{DeprecatedTask}}
[http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/ativan_9901.htm ativan online] [http://users.wpi.edu/~dance/blahdocs/uploads/lorazepam_3885.htm lorazepam online] [http://users.wpi.edu/~dance/blahdocs/uploads/alprazolam_3561.htm alprazolam online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=186 free jazz ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30259 alprazolam online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/phentermine_8208.htm cheap phentermine] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=191 cheap lorazepam] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=138 verizon ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2912 free sagem ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/carisoprodol_1193.htm cheap carisoprodol] [http://students.hsc.unt.edu/housing/item.cfm?type=2911 free cingular ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/realringtones_3783.htm free real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=96 levitra online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3749 cheap ultracet] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30349 cingular ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3737 cheap phentermine] [http://wc1.worldcrossing.com/WebX/.1de60a0b vigrx online] [http://wc1.worldcrossing.com/WebX/.1de60a28 cheap soma] [http://library.cshl.edu/wp/vb/member.php?u=1371 funny ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2868 cheap ambien] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=126 cheap sildenafil] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=129 free sony ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3762 funny ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/paxil_2293.htm buy paxil] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3755 cheap ortho] [http://library.cshl.edu/wp/vb/member.php?u=1360 lorazepam online] [http://users.wpi.edu/~dance/blahdocs/uploads/freeringtones_1986.htm free free ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1348 cheap ativan] [http://wc1.worldcrossing.com/WebX/.1de60a24 cheap propecia] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30336 qwest ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/paxil_4058.htm paxil online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3706 wellbutrin online] [http://library.cshl.edu/wp/vb/member.php?u=1367 didrex online] [http://library.cshl.edu/wp/vb/member.php?u=1364 nexium online] [http://library.cshl.edu/wp/vb/member.php?u=1342 cheap phentermine] [http://library.cshl.edu/wp/vb/member.php?u=1376 free motorola ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a25 free samsung ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a2d cheap valium] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30277 cyclobenzaprine online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30243 ultram online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30327 buy zyban] [http://students.hsc.unt.edu/housing/item.cfm?type=2916 alltel ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1339 tramadol online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=212 propecia online] [http://students.hsc.unt.edu/housing/item.cfm?type=2910 free polyphonic ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=177 diethylpropion online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=175 cheap diazepam] [http://library.cshl.edu/wp/vb/member.php?u=1380 verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30296 clomid online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3767 polyphonic ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3763 free nextel ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f7 free nextel ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=98 lisinopril online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=118 buy prozac] [http://wc1.worldcrossing.com/WebX/.1de60a1e flexeril online] [http://wc1.worldcrossing.com/WebX/.1de60a35 verizon ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/nextelringtones_3485.htm free nextel ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3695 cheap carisoprodol] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=241 sony ericsson ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3723 free motorola ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30318 diethylpropion online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30253 cheap norco] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30350 free sagem ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1372 mp3 ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1d free cingular ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=168 celexa online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=221 order vicodin] [http://library.cshl.edu/wp/vb/member.php?u=1350 order meridia] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30363 free sony ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=202 nokia ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=84 diethylpropion online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3716 buy diethylpropion] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=233 sonyericsson ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30266 cheap lorazepam] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/ultracet_2738.htm cheap ultracet] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=230 verizon ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3738 xanax online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=83 didrex online] [http://library.cshl.edu/wp/vb/member.php?u=1343 carisoprodol online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30365 free mtv ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/freeringtones_8902.htm free free ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3696 online fioricet] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=136 cheap ultram] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/norco_532.htm norco online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3766 free music ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=170 free cingular ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=90 cheap hgh] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/propecia_2137.htm propecia online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/ambien_7869.htm buy ambien] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3750 didrex online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=189 lipitor] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=139 cheap viagra] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3699 cheap meridia] [http://students.hsc.unt.edu/housing/item.cfm?type=2851 carisoprodol online] [http://students.hsc.unt.edu/housing/item.cfm?type=2918 free cool ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30316 order vigrx] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/verizonringtones_8798.htm verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30330 free nokia ringtones] [http://wc1.worldcrossing.com/WebX/.1de609de cheap alprazolam] [http://wc1.worldcrossing.com/WebX/.1de609e5 cool ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1359 ambien online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=82 diazepam online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=206 cheap pharmacy online] [http://users.wpi.edu/~dance/blahdocs/uploads/nokiaringtones_4263.htm nokia ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3741 viagra online] [http://library.cshl.edu/wp/vb/member.php?u=1382 cingular ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2905 motorola ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1358 cheap hydrocodone] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30309 cheap celexa] [http://users.wpi.edu/~dance/blahdocs/uploads/nexium_6814.htm nexium online] [http://library.cshl.edu/wp/vb/member.php?u=1363 cyclobenzaprine online] [http://wc1.worldcrossing.com/WebX/.1de60a1b music ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2914 free sony ericsson ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3729 mono ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3734 sony ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f9 norco online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=97 lipitor online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3747 xenical] [http://users.wpi.edu/~dance/blahdocs/uploads/ultram_1401.htm cheap ultram] [http://students.hsc.unt.edu/housing/item.cfm?type=2849 cheap valium] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=85 ericsson ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2877 cheap prozac] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3743 cheap vicodin] [http://library.cshl.edu/wp/vb/member.php?u=1388 fioricet online] [http://students.hsc.unt.edu/housing/item.cfm?type=2854 ultram] [http://wc1.worldcrossing.com/WebX/.1de60a21 paxil online] [http://library.cshl.edu/wp/vb/member.php?u=1368 free nokia ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3754 celexa] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3717 hgh online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=197 free mp3 ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2882 zoloft online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3752 albuterol online] [http://students.hsc.unt.edu/housing/item.cfm?type=2862 vicodin online] [http://library.cshl.edu/wp/vb/member.php?u=1378 free sprint ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30244 cheap diazepam] [http://wc1.worldcrossing.com/WebX/.1de609f3 midi ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a16 online levitra] [http://users.wpi.edu/~dance/blahdocs/uploads/ativan_8101.htm cheap ativan] [http://wc1.worldcrossing.com/WebX/.1de609fd free punk ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=95 kyocera ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=215 zoloft online] [http://students.hsc.unt.edu/housing/item.cfm?type=2904 real ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=207 xanax online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/fioricet_7129.htm cheap fioricet] [http://students.hsc.unt.edu/housing/item.cfm?type=2920 free midi ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=182 free funny ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/vicodin_8272.htm vicodin online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30356 cool ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1369 free free ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2867 cheap hydrocodone] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3770 alltel ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3703 cheap hydrocodone] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3724 free sprint ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=79 clonazepam online] [http://students.hsc.unt.edu/housing/item.cfm?type=2896 buy zyban] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=132 tenuate online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=147 zoloft online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30280 propecia online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=194 midi ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3759 cheap flexeril] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=213 cheap prozac] [http://wc1.worldcrossing.com/WebX/.1de609df cheap ambien] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/viagra_2557.htm viagra online] [http://students.hsc.unt.edu/housing/item.cfm?type=2902 free nextel ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=117 propecia online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=172 but clonazepam] [http://students.hsc.unt.edu/housing/item.cfm?type=2856 cialis online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3720 tracfone ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=143 free wwe ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/wellbutrin_1044.htm wellbutrin online] [http://students.hsc.unt.edu/housing/item.cfm?type=2926 free jazz ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2876 buy didrex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=116 free polyphonic ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a2e cheap xanax] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/nokiaringtones_9955.htm nokia ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/polyphonicringtones_8614.htm polyphonic ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=88 free ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/valium_3.htm valium online] [http://wc1.worldcrossing.com/WebX/.1de60a31 buy zanaflex] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30245 online cialis] [http://users.wpi.edu/~dance/blahdocs/uploads/cialis_7892.htm cialis online] [http://students.hsc.unt.edu/housing/item.cfm?type=2885 tenuate online] [http://students.hsc.unt.edu/housing/item.cfm?type=2906 samsung ringtones] [http://users.wpi.edu/~dance/blahdocs/uploads/xanax_3394.htm cheap xanax] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=122 rivotril online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3731 sharp ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30312 cheap ortho] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30230 adipex] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3712 lipitor] [http://wc1.worldcrossing.com/WebX/.1de60a30 xenical online] [http://wc1.worldcrossing.com/WebX/.1de60a1a free mtv ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/wellbutrin_1082.htm wellbutrin online] [http://wc1.worldcrossing.com/WebX/.1de60a23 polyphonic ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=115 cheap phentermine] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=106 free mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a06 cheap tenuate] [http://users.wpi.edu/~dance/blahdocs/uploads/motorolaringtones_4301.htm free motorola ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3775 free jazz ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3721 free mp3 ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30338 motorola ringtones] {{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 to MyArray

Dynamic array free:
MyArray free
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.