Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

Vote on your favorite hash algorithm here!

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-2006, 01:17 PM
Sionofdarkness Sionofdarkness is offline
Programming Expert
 
Join Date: Jul 2006
Posts: 385
Credits: 0
Rep Power: 11
Sionofdarkness is on a distinguished road
Default Arrays

I've just heard of this, and I know it has something to do with pointers (but I don't even know what pointers do yet). I know arrays also have positions, and I'm guessing pointers "point" to arrays in different positions, but I am really unsure.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-21-2006, 05:06 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,535
Last Blog:
wxWidgets is NOT code ...
Credits: 919
Rep Power: 28
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

An array is a variable that stores multiple pieces of data of the same type. This corresponds to the idea that an apartment building can store more than one family at the same address. Since each family needs to get their own mail, they are referenced by apartment number. Arrays use a similar technique to access their members.
Code:
int main()
{
  int MyArray[5]=( 1, 3, 5, 7, 9 );
  return MyArray[0];
}
This snippet sets up an array of 5 ints, all referred to by the name MyArray. The indices in C/C++ are 0,1,2,3,4. The individual elements of the array are:
MyArray[0] == 1
MyArray[1] == 3
MyArray[2] == 5
MyArray[3] == 7
MyArray[4] == 9
The name MyArray can be used as a pointer that points to MyArray[0]
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-24-2006, 09:04 PM
Crane's Avatar   
Crane Crane is offline
Programming Expert
 
Join Date: Nov 2005
Posts: 399
Credits: 1
Rep Power: 13
Crane is on a distinguished road
Default

Perfect wingedpanther! Rep given.

You can also have multi-dimensional arrays
MyArray[0][1] = 1
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-25-2006, 05:58 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,535
Last Blog:
wxWidgets is NOT code ...
Credits: 919
Rep Power: 28
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

Dang! I didn't even know we could get rep. I wouldn't have noticed if you didn't mention it, Crane.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-26-2006, 04:12 PM
kromagnon kromagnon is offline
Learning Programmer
 
Join Date: Jun 2006
Posts: 53
Credits: 0
Rep Power: 9
kromagnon is on a distinguished road
Default

Quote:
I know it has something to do with pointers
yes. All the elements in an array are stored consecutively in memory, and when you declare the array type, the compiler knows how far apart to allot space for them in memory. The array index(the number in the brackets) tells how much to offset the memory address from the first item in memory. For example: if i declare
Code:
int MyArray[5]
then each item in the array is 32 bits, so the first item: (MyArray[0]) is 0 bits away from the beginning of the array, while the 3rd item in the array (MyArray[2]) is 2*32 = 64 bits away from the first item in the array, so the address in memory is ((address of first element) + 64)

if an array is used incorrectly, you will read memory outside the bounds of the array, for example, if I try to find the value of MyArray[9] , it will give me a value, it will just turn whatever junk is stored in those 32 bits in memory into an int. You can also access memory in front of the array as well, for example: MyArray[-1] will return the value 32 bits before the first item.
__________________
<!-- comment comment comment --></

Last edited by kromagnon; 07-26-2006 at 04:17 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 07-26-2006, 05:35 PM
icepack's Avatar   
icepack icepack is offline
Programmer
 
Join Date: Jul 2006
Location: North Carolina
Posts: 115
Credits: 12
Rep Power: 9
icepack is on a distinguished road
Send a message via AIM to icepack
Default

When learning C++, pointers was the hardest concept for me to get. But once I got on track, it made my Data Structures class so much easier.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python arrays... Sir_Rimo Python 3 06-20-2007 08:54 AM
variable length arrays in C rattlepanos C and C++ 3 05-03-2007 11:35 AM
Arrays clookid PHP Tutorials 1 01-11-2007 08:30 PM
Are arrays sort of like matrices? Sionofdarkness Java Help 5 08-21-2006 02:30 PM
Arrays in NET 2.0 or CLI Managed C++ Void Managed C++ 1 07-18-2006 07:57 PM


All times are GMT -5. The time now is 09:14 AM.

Contest Stats

Xav ........ 1357.94
MeTh0Dz|Reb0rn ........ 1083.85
WingedPanther ........ 919.18
morefood2001 ........ 909.18
marwex89 ........ 906.86
John ........ 902.37
Brandon W ........ 789.89
chili5 ........ 312.39
Steve.L ........ 264.99
dcs ........ 240.34

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 83%

Ads