Array: Difference between revisions
m (Accidentilly used single quotes instead of doubles. Corrected.) |
InvaderZim (talk | contribs) (Working on Variables category, almost all stubs) |
||
Line 1: | Line 1: | ||
[[category:variables]] | [[category:variables]] | ||
'''Array'''s are a set of [[variable]]s of the same type with | '''Array'''s are a set of [[variable]]s of the same type with amount of memory | ||
An example of an array is below: | An example of an array is below: | ||
int lotsOfInts[100] | int lotsOfInts[100]; | ||
This declares an [[integer]] '''array''', with at maximum 100 members. | This declares an [[integer]] '''array''', with at maximum 100 members. | ||
This is because when a compiler sees the ''100'' within the braces it knows to allocate enough memory to the '''array''' to hold 100 [[integer]]s. | |||
When accessing a member of an '''array''' it is important to remember that they are numbered starting at zero. | |||
Therefore | |||
lotsOfInts[3]; | |||
actually refers to the 4th [[integer]] member of the '''array'''. | |||
Strings can be created by making a [[char]]acter '''array''', as seen below. | Strings can be created by making a [[char]]acter '''array''', as seen below. | ||
char thisIsAString[5]; | char thisIsAString[5]; | ||
thisIsAString[0]= | thisIsAString[0]='H'; | ||
thisIsAString[1]= | thisIsAString[1]='e'; | ||
thisIsAString[2]= | thisIsAString[2]='l'; | ||
thisIsAString[3]= | thisIsAString[3]='l'; | ||
thisIsAString[4]= | thisIsAString[4]='o'; | ||
Or this can be performed in one action as follows: | |||
char thisIsAString[] = | char thisIsAString[5] = {'H','e','l','l','o'}; | ||
However strings are more commonly stored in a [[char]]*, a character [[pointer]] | |||
[[pointer]]s can be used fairly similarly to '''arrays''' | |||
'''Array''' members can also be accessed via [[pointer]]s. | '''Array''' members can also be accessed via [[pointer]]s. | ||
Custom classes can be used in '''arrays'''. | Custom classes can be used in '''arrays'''. | ||
[[Vector]]s are an alternative to '''arrays'''. | [[Vector]]s are an alternative to '''arrays''' that allow more mathematical operations suited to manipulating various quantities related to geometry and physics, such as force [[vector]]s and normal [[vector]]s. | ||
Revision as of 13:14, 7 August 2005
Arrays are a set of variables of the same type with amount of memory
An example of an array is below:
int lotsOfInts[100];
This declares an integer array, with at maximum 100 members. This is because when a compiler sees the 100 within the braces it knows to allocate enough memory to the array to hold 100 integers.
When accessing a member of an array it is important to remember that they are numbered starting at zero. Therefore
lotsOfInts[3];
actually refers to the 4th integer member of the array. Strings can be created by making a character array, as seen below.
char thisIsAString[5]; thisIsAString[0]='H'; thisIsAString[1]='e'; thisIsAString[2]='l'; thisIsAString[3]='l'; thisIsAString[4]='o';
Or this can be performed in one action as follows:
char thisIsAString[5] = {'H','e','l','l','o'};
However strings are more commonly stored in a char*, a character pointer pointers can be used fairly similarly to arrays
Array members can also be accessed via pointers.
Custom classes can be used in arrays.
Vectors are an alternative to arrays that allow more mathematical operations suited to manipulating various quantities related to geometry and physics, such as force vectors and normal vectors.