From Valve Developer Community
Jump to: navigation, search
Deutsch Español

Arrays are a set of variables of the same type with a built in capacity

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


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];

Or this can be performed in one action as follows:

	char thisIsAString[5] = {'H','e','l','l','o'};

The same style of setting up an array applies to any type of variable. 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.