|
Don't leave this site coz its invaluable. Yes there mean people out there but they are sadly here to stay.
An array is just a variable that stores more than one value at the same time. I assume you know what a variable is so take an int variable as an example. An int variable can only store one value at any given time so it can't hold a collection of values, say the total number of students in each class of a school. This is where an array comes handy.
An array usually stores values of only one type so you can't mix integers with strings unless the array has been set to contain type Object.
An array stores these items in a column like manner. So we have the first item at the top, the second item follows and so on. Each item has index that indicates its position in the array. The first item usually occupies index 0, the second index 1, the third index 2 and the list continues depending on how many items the array has been set to hold.
To declare an array that stores five items of type integer in c# code proceed as follows;
int[] noOfStudents = new int[5];
we now have an array that explicitly stores only values that are of type integer (whole numbers only). To set the first item to hold 20 use the following code:
noOfStudents[0]=20;
since the array has been set to hold a maximum of 5 values, the last index (the position an item is found at) is therefore 4 since we start counting from index 0.
To get an item in the third index proceed as follows:
int value=noOfStudents[2];
remember we start counting from index 0. If you try to set a value at index 45 and the array has been set to hold 20 values then you will get an error/exception. Likewise if you try to set a value to an element that is beyond the maximum possible items that the array has been set to hold then you will get an error that may state (out of bounds exception). Read more on arrays coz this was just an introduction. Hope it helped you.
|
|
|
|
|
The gui who asked "what is an array" had already written 14 articles on CP (just look is profile...)
The question was meant to be existential, not "technical".
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Yeah, figured I'd help the next noob who came along doing a class assignment on arrays. Was also kinda drunk and feeling generous.
|
|
|
|
|
But yeah, he got me. Should be the most epic April Fools joke
|
|
|
|
|
Come on guys. Give new people a break. Have we forgotten how we started? Remember: "Every master was once a disaster".
|
|
|
|
|
Are you really this retarded, or are you making a piss-poor attempt at being funny?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Yes, I am making a piss-poor attempt at being funny, and I am really happy having these pathetic replies! Now this is really funny.
|
|
|
|
|
Alex Fr wrote: what is array?
A kind of fish.
Alex Fr wrote: what is index?
Usually wood or steel.
Are you sure you are on the correct site? This is the Code project, not the cod project.
|
|
|
|
|
Thanks, but another answer I have is that they are like like pizza and tomato. It looks so confusing...
|
|
|
|
|
|
Wow dude , really you are at the wrong place.
I am of opinion that an array should always start at 0 becuase of the decimal system, starts at 0, and -1 is a good way to show that nothing was selected
"And why there are no multiple choice" - even if the choice has two possible answer it is still "multiple"
"and free answers?" - Because tehres are members of programming forums that has no clue what an array is
Chona1171
Web Developer (C#), Silverlight
|
|
|
|
|
Multiple choice allows to select more than one answer! It looks like you are at the wrong place
But what the hell is array ???
|
|
|
|
|
you have two possible answers and last time i checked (2 > 1) == true;
Basic English should tell you that:
An array is a systematic arrangement of objects, usually in rows and columns.
Referred to in the following fields of study:
Computer science
math and stats
biology
astronomy
technology
and music
So here's my question why join a programming forum ?
Chona1171
Web Developer (C#), Silverlight
|
|
|
|
|
Chona1171 wrote: So here's my question why join a programming forum ?
Because I am programmer!
Thanks for your explanation. My vote of 5
|
|
|
|
|
Ah checked your profile you taking a wizz on everyone.
Good one , he simply playing noob. Didnt realize i actually references a couple of your articles for research.
Chona1171
Web Developer (C#), Silverlight
|
|
|
|
|
Alex Fr wrote: What is array? And index?
They're like pizza and tomato, a bit less tasty.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Well, at least you are trying to explain... Thanks!!
|
|
|
|
|
Maybe you have learnt at least what is an Array from Codeproject. You should not complain now...
|
|
|
|
|
In the beginning God created the variables.
Variables were always messing around, they got home late at night, and were usually drunk.
They were so many and so uncontrollable that God was starting to get tired of creating things.
So God created the array, where several variables could be handled all at once,
and he saw that it was good.
Since he was so happy with the arrays he created the light the Earth the animals and the humans.
|
|
|
|
|
Wow! This is really great. I am happy that I posted my stupid joke after reading this. Maybe you have similar explanation about indexes?
|
|
|
|
|
Thanks, apparently those English Composition classes are paying off.
What's really funny is that people don't get the joke and think that you are actually retarded
|
|
|
|
|
Despite this is actually a joke, it can be taken very seriously.
Especially if we consider the forum question "... In high-level languages ..."If we also ask what are "high level languages", and provide some contextual definition, the answers can vary a lot!
Hence, the proper format should really had been
-> 0
-> 1
-> any
And I had probably chosen "any".
I voted "0" just because I found "1" arbitrary, but I really think that in a "high level language" array bounds should be specific for each array to reflect what the array itself represents respect to the world it is modeling.
The discrete value of a function can be y[x] with x=(-100..+100;2) (meaning: from -100 to +100 stepping by 2) and yes: it is right to have exceptions if you address wrong indexes.
Some people say this is confusing. But is no more confusing than operator overloading, after all.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
#define BASEADDR (0xFFFF0000)
char* hardwareX = BASEADDR;
hardwareX[0] = 'a';
printf("%d\n", &(hardwareX[0]));
prints: 0xFFFF0000
printf("%d\n", &(hardwareX[1]));
prints: 0xFFFF0001
printf("%d\n", &(hardwareX[2]));
prints: 0xFFFF0002
printf("%d\n", &(hardwareX[3]));
prints: 0xFFFF0003
Seems very logical to me to use zero based indices
"Program testing can be used to show the presence of bugs, but never to show their absence."
<< please vote!! >>
|
|
|
|
|
|
Seriously, I cannot decide what to vote for, when I do have no CListCtrl option. Please add!
|
|
|
|