Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 18th, 2005, 3:53 AM   #11
Gunman
Programmer
 
Gunman's Avatar
 
Join Date: Oct 2005
Posts: 56
Rep Power: 3 Gunman is on a distinguished road
How do i do it ?
Gunman is offline   Reply With Quote
Old Oct 18th, 2005, 3:55 AM   #12
Gunman
Programmer
 
Gunman's Avatar
 
Join Date: Oct 2005
Posts: 56
Rep Power: 3 Gunman is on a distinguished road
Nvm..I got it ..I will change it ..
Gunman is offline   Reply With Quote
Old Oct 18th, 2005, 3:59 AM   #13
Gunman
Programmer
 
Gunman's Avatar
 
Join Date: Oct 2005
Posts: 56
Rep Power: 3 Gunman is on a distinguished road
I can't seem to edit my post so next time when i post i would use code tags ..
Gunman is offline   Reply With Quote
Old Oct 18th, 2005, 4:21 AM   #14
anant_tickoo
Programmer
 
Join Date: Sep 2005
Posts: 50
Rep Power: 0 anant_tickoo is an unknown quantity at this point
use code tag like this [ C O D E ] your code [/ C O D E ]

just do't use spaces in code tage. its like html code.

or click # sign in ur advance windows of reply post.
anant_tickoo is offline   Reply With Quote
Old Oct 18th, 2005, 5:59 AM   #15
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Quote:
Originally Posted by Gunman
Hey can someone kinda of explain to me about arrays ? I have information about arrays but can't really understand them . I would like to know some basic uses of array and how and when they are used..and about one dimensional and two dimensional arrays . Thanks =)
Hope this help a little: http://programmingforums.org/forum/s...ead.php?t=1644

It's C but I hope it should still help.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Oct 18th, 2005, 1:05 PM   #16
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,038
Rep Power: 5 lectricpharaoh will become famous soon enough
The main use of arrays is to manipulate a set of things (objects or variables) that are all of the same type. This allows you to write the code to do the manipulation once, rather than once for each value. You can then loop through, starting with the first element you wish to process, and ending at the last.

Remember that arrays are always zero-based; that is, the first element is element zero, not element one, and the last is numbered as one less than the size. This means if you're looping through an array, make sure you don't go beyond the bounds; the compiler does not check if you exceed the bounds of the array, so you have to do this yourself. Nor does your program throw an exception at runtime, as a Java program will. Note that, in some special circumstances, you actually will want to go beyond the boundaries you've declared for your arrays (the only case I can think of offhand is when you use an array as the last element of a structure, and then dynamically allocate memory for your structure plus some 'extra'), but cases like this are rare, and when you do it, be sure you know why you're doing it.

In C and C++, arrays and pointers are closely related. A pointer is a variable that stores an address of something else (an object, variable, or function), and an address is just the location at which it resides in memory. Pointers are useful because you can access a chunk of memory through the pointer, which is often more efficient. For example, let's assume my system has ints that are 32 bits, and pointers that are 32 bits (this is a very common scenario on modern machines). Now let's say I have an array of 1024 ints. If I pass the whole array (ie, each value separately), that is a lot of parameters I have to pass, and consequently, a lot of work that needs to be done every time the function gets called. On the other hand, I could pass a single pointer to the start of the array, and the called function could then access the entire array through this pointer.

C and C++ support this sort of coding by having arrays and pointers be somewhat interchangeable. The idea is that any array name without a subscript (the number in the brackets), or with fewer subscripts than the array actually has (ie, one subscript for a two-dimensional array) is treated as an address. As such, you can assign it to a pointer, and you can use array notation on pointers. However, there are some things to know about. First is that an array's memory is at a fixed location- you can assign its address to a pointer, but cannot assign to its address (this is for much the same reason that x = 5 is legal, whereas 5 = x is not). Second is that true arrays (often called 'static arrays') allocate memory for the requested number of elements; hence, sizeof(array) is equal to the number of elements times sizeof(arrayElement); pointers, on the other hand, have a fixed size (often, but not always, the same as an int on the system in question). Last is that pointers need to be initialized before using them to access what they point at. Remember that variables in C and C++ are not initialized by default (except for those declared as static, or outside all functions), and pointers are no exception. Using an uninitialized pointer will at best yield garbage output, and at worst may do some serious damage (you're mucking with memory at essentially random locations), though many modern systems will terminate programs that try to access memory they don't own.

There are also other uses of pointers, such as 'returning' more than one value from a function (this was common in C, but isn't used as much in C++, thanks to 'reference variables'), allocating dynamic arrays (simply allocating a chunk of memory at runtime, and accessing it through the pointer, just as Polyphemus_ did in his example), and other things.

For more on pointers, you should see DaWei's article on them; the link is in his sig. It's worth the read, but if you don't understand them right away, that's normal. Pointers generally take a bit of work to understand, but once you do, you'll be amazed how easy they really are to use.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Oct 19th, 2005, 4:27 AM   #17
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Nicely explained and nice to see you back pharoaoh (after 2 months).
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Oct 20th, 2005, 6:11 AM   #18
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,038
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by nnxion
Nicely explained and nice to see you back pharoaoh (after 2 months).
Thanks. Been busy with school and RL, but decided to drop by. Good to see familiar faces along with some new ones.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:05 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC