Page 1 of 1

Arrays Explained Description in Simple Terms what an array is. Rate Topic: ***** 2 Votes

#1 KeyWiz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 438
  • Joined: 26-October 06

Posted 28 October 2006 - 11:42 AM

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
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 November 2006 - 03:27 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Arrays Explained

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1865
  • View blog
  • Posts: 20,278
  • Joined: 17-March 01

Posted 28 October 2006 - 11:50 AM

All in favor of moving this to the tutorial area say AYE
Was This Post Helpful? 0
  • +
  • -

#3 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Posted 28 October 2006 - 12:46 PM

Aye - and perhaps a title change as well. :)
Was This Post Helpful? 0
  • +
  • -

#4 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Posted 29 October 2006 - 12:18 PM

Aye
Was This Post Helpful? 0
  • +
  • -

#5 eLliDKraM  Icon User is offline

  • Pepè Le Pewn
  • member icon

Reputation: 6
  • View blog
  • Posts: 6,565
  • Joined: 13-August 05

Posted 29 October 2006 - 12:32 PM

I
Was This Post Helpful? 0
  • +
  • -

#6 Videege  Icon User is offline

  • rêvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Posted 29 October 2006 - 12:58 PM

Well then I'll do the honors -> moved to VB tutorials just because that's the language used in the example.
Was This Post Helpful? 0
  • +
  • -

#7 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1865
  • View blog
  • Posts: 20,278
  • Joined: 17-March 01

Posted 31 October 2006 - 07:09 AM

Kudos added.
Was This Post Helpful? 0
  • +
  • -

#8 torch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-May 07

Posted 09 May 2007 - 03:40 PM

View Postskyhawk133, on 28 Oct, 2006 - 11:50 AM, said:

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

AYE!!!
Was This Post Helpful? 0
  • +
  • -

#9 damarausa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-May 07

Post icon  Posted 10 May 2007 - 08:52 PM

AYE
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1