Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,456 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,400 people online right now. Registration is fast and FREE... Join Now!




Arrays Explained

 
Reply to this topicStart new topic

> Arrays Explained, Description in Simple Terms what an array is.

Rating  5
KeyWiz
Group Icon



post 28 Oct, 2006 - 10:42 AM
Post #1


Arrays are simply Lists.

Consider this Grocery list, it is a One Dimentional Array.

Eggs
Milk
Bread
Letuce
Hamburger
Swiss Cheese
etc.

To represent this in code we have to tell the computer that we want to keep a list of Related Items. We do this by Declairing The Array and setting it's data type, which allows the computer to set aside the EXACT amount of memory needed for that list.

in most programming languages an Array is represented by a Designation similar to Dim myArray(n) where n = any number. If you replace n with a value, then memory is reserved for n items.

example simple 1 Dimentional Array
CODE

Dim Groceries(20) as String

    'Assign Values to the Array
    Groceries(0) = "Eggs"
    Groceries(1) = "Milk"
    Groceries(2) = "Bread"
    Groceries(3) = "Letuce"
    Groceries(4) = "Hamburger"
    Groceries(5) = "Swiss Cheese"


etc.

But for most people an Array is best Visualized in two dimentions Length (X) and Height(Y)

Think of a Chess Board. Each Box can have a piece in it, and each piece is at a specific box. By creating an Array called Chess(8,8) we can place data at each Addressed Box representing the piece at that location. There are 64 locations in this Array. We could create a single dimention Array of 64 units ie Chess(64) and have the same size Array, but this would make programming the interaction between pieces very dificult. by making the 2D Array we can Visualize The Board and easily represent movements and associations by simple math. ie

Chess(4,4) = BlackQueensPawn

to move the piece one place forward we simply add 1 to the Y address position and place the data there

Chess(4,5) = BlackQueensPawn

And erase the value where it was

Chess(4,4) = ""

note: Computer Arrays always start with a beginning position of 0, so to a computer the Starting Position for BlackQueensRook would be Chess(0,0) top left corner, or you could call it the bottom left corner if you wished. The point is that each square on the board is represented by a place identifyer, or Address,
Chess(0,0) = BlackQueensRook
Chess(0,1) = BlackQueensKnight
Chess(0,3) = BlackQueensBishop
and so on.

In a one dimentional array, the Y value is always 0 therefore, it need not be addressed in code. therefore a 1 dimentional Array is always a horizontal list. City = List(X) {read as "City equals List at X}

a Two Dimentional Array would be City = Box(X,Y) {read as City equals Box at X by Y.}

a Three Dimentional Array would Be City = Cube(X,Y,Z) {read as City equals Cube at X by Y by Z}

If you haven't caught on yet a Three Dimentional Array can be used to set the location of a value in a 3D environment

If you wanted to construct a Four Dimentional Array, it could represent the city at T by X by Y by Z or City(T,X,Y,Z)
N for Name. So you could address the city as
City(Time,Longitude,Latitude,Altitude) and so on.

Not so important today as it was 20 years ago, but Each dimention you add to an equally sized array ie (2,2) (3,3) (5,5,5) etc. increases the amount of memory used by a factor of the value.
A (2,2) Array will use 4 memory addresses, a (2,2,2) will use 8 and (2,2,2,2) would use 16 memory addresses and so on.

(4,4) = 16
(4,4,4) = 64
(4,4,4,4) = 256

if you will notice these are all the "MAGIC COMPUTER NUMBERS" because we are basically dealling with BINARY when we use a two dimentional Array. This is exactly how the computer itself keeps track of everything. Memory is a very large Three Dimentional Array. Each Bit in memory has a specific address in this Array. The computer simply keeps track of which memory addresses are related to each other and they each simply hold a 1 or a 0.

Memory at RamChip by ByteLocation by BitPosition as Binary

Memory(RamChip,ByteLocation,BitPosition) as Binary

Memory(1,2563,61) = 1
Memory(1,2563,62) = 0
Memory(1,2563,63) = 1

etc.

I hope this helps.

This post has been edited by KeyWiz: 13 Nov, 2006 - 02:27 PM
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

skyhawk133
Group Icon



post 28 Oct, 2006 - 10:50 AM
Post #2
All in favor of moving this to the tutorial area say AYE
Go to the top of the page
+Quote Post

Amadeus
Group Icon



post 28 Oct, 2006 - 11:46 AM
Post #3
Aye - and perhaps a title change as well. smile.gif
Go to the top of the page
+Quote Post

snoj
Group Icon



post 29 Oct, 2006 - 11:18 AM
Post #4
Aye
Go to the top of the page
+Quote Post

eLliDKraM
Group Icon



post 29 Oct, 2006 - 11:32 AM
Post #5
I
Go to the top of the page
+Quote Post

Videege
Group Icon



post 29 Oct, 2006 - 11:58 AM
Post #6
Well then I'll do the honors -> moved to VB tutorials just because that's the language used in the example.
Go to the top of the page
+Quote Post

skyhawk133
Group Icon



post 31 Oct, 2006 - 06:09 AM
Post #7
Kudos added.
Go to the top of the page
+Quote Post

torch
*



post 9 May, 2007 - 02:40 PM
Post #8
QUOTE(skyhawk133 @ 28 Oct, 2006 - 11:50 AM) *

All in favor of moving this to the tutorial area say AYE

AYE!!!
Go to the top of the page
+Quote Post

damarausa
*



post 10 May, 2007 - 07:52 PM
Post #9
AYE
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 11/22/08 12:09PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month