Revision history for TutIntroArrays


Revision [22224]

Last edited on 2018-02-11 11:25:36 by JeffMarshall [escape camel-case words]
Additions:
Arrays are probably the single most useful programming construct that is available to you in ""FreeBASIC"". Many problems that you will try to solve with a programming solution involve data arranged in tabular format, and arrays are perfect for managing this type of data. Understanding arrays is a crucial skill in becoming a competent programmer.
Arrays are contiguous memory segments of a single or composite data type. You can think of an array as a table, with rows and columns of data. An array can have one or more rows, and each row can have one or more columns. The number of rows and columns define the dimensions of the array. ""FreeBASIC"" uses the row-major scheme for arrays, which means that the first dimension references the row in an array that has more than one dimension. ""FreeBASIC"" supports up to eight dimensions in an array.
An array with a single row is called a one-dimensional array. If an array is a single-dimensional array, then the row is not defined in the declaration, only the number of columns in the row. Since an array requires a minimum of one row, the row is understood to exist in this case. The following code snippets create a single-dimension integer array using the different array definition schemes available in ""FreeBASIC"".
In this example, the first block, ##{1, 2, 3, 4, 5}##, corresponds to row 1, and the second block, ##{6, 7, 8, 9, 10}##, corresponds to row 2. Remember that ""FreeBASIC"" arrays are row-major, so the row is specified before the column. When you initialize an array in this manner, you must be sure that the number of elements defined will fit into the array.
Deletions:
Arrays are probably the single most useful programming construct that is available to you in FreeBasic. Many problems that you will try to solve with a programming solution involve data arranged in tabular format, and arrays are perfect for managing this type of data. Understanding arrays is a crucial skill in becoming a competent programmer.
Arrays are contiguous memory segments of a single or composite data type. You can think of an array as a table, with rows and columns of data. An array can have one or more rows, and each row can have one or more columns. The number of rows and columns define the dimensions of the array. FreeBasic uses the row-major scheme for arrays, which means that the first dimension references the row in an array that has more than one dimension. FreeBasic supports up to eight dimensions in an array.
An array with a single row is called a one-dimensional array. If an array is a single-dimensional array, then the row is not defined in the declaration, only the number of columns in the row. Since an array requires a minimum of one row, the row is understood to exist in this case. The following code snippets create a single-dimension integer array using the different array definition schemes available in FreeBasic.
In this example, the first block, ##{1, 2, 3, 4, 5}##, corresponds to row 1, and the second block, ##{6, 7, 8, 9, 10}##, corresponds to row 2. Remember that FreeBasic arrays are row-major, so the row is specified before the column. When you initialize an array in this manner, you must be sure that the number of elements defined will fit into the array.


Revision [22200]

Edited on 2018-02-10 13:20:39 by JeffMarshall [escape camel-case words]
Additions:
##""MyCube(10, 10, 10)""## would create a cube with 11 vertical units, 0 to 10, 11 horizontal units, 0 to 10 and 10 depth units, 0 to 10. To access the center of the cube, you would use ##iCenter = myCube(5, 5, 5)##.
You specify a dynamic array by using the ##""ReDim""## keyword.
In this case the compiler sets a default value of 0 for the array size. You can then use the ##""ReDim""## at some point in the program to set the array bounds.
=== ""ReDim"" and ""ReDim"" Preserve ===
Dynamic arrays can change sizes during execution. ##""ReDim""## will clear the contents of the array to the default data type values, while ##""ReDim Preserve""## will keep intact the existing contents, unless the array size is smaller than the previous size.
Deletions:
##MyCube(10, 10, 10)## would create a cube with 11 vertical units, 0 to 10, 11 horizontal units, 0 to 10 and 10 depth units, 0 to 10. To access the center of the cube, you would use ##iCenter = myCube(5, 5, 5)##.
You specify a dynamic array by using the ##ReDim## keyword.
In this case the compiler sets a default value of 0 for the array size. You can then use the ##ReDim## at some point in the program to set the array bounds.
=== ReDim and ReDim Preserve ===
Dynamic arrays can change sizes during execution. ##ReDim## will clear the contents of the array to the default data type values, while ##ReDim Preserve## will keep intact the existing contents, unless the array size is smaller than the previous size.


Revision [22186]

Edited on 2018-02-07 00:46:32 by sancho3 [escape camel-case words]
Additions:
//Last Reviewed by ""Sancho3"" on February 06, 2018//


Revision [20693]

Edited on 2016-02-10 16:15:09 by DkLwikki [Update link format]
Additions:
//Written by [[WikiRick|rdc]]//
There are a number of [[CatPgArray|functions]] that you can use with arrays.
Deletions:
//Written by [[WikiRick rdc]]//
There are a number of [[CatPgArray functions]] that you can use with arrays.


Revision [15542]

Edited on 2011-12-10 20:29:50 by CountingPine [“” to ""]
Additions:
The -exx compiler switch will enable error and bounds checking within your program. If you go outside the bounds of an array within your program, the compiler will generate an "out of bounds" error while the program is running.
Deletions:
The -exx compiler switch will enable error and bounds checking within your program. If you go outside the bounds of an array within your program, the compiler will generate an “out of bounds” error while the program is running.


Revision [12143]

The oldest known version of this page was created on 2008-01-05 16:18:16 by ElSairon [“” to ""]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode