Difference between revisions of "Array"

From Valve Developer Community
Jump to: navigation, search
m
m (Accidentilly used single quotes instead of doubles. Corrected.)
Line 11: Line 11:
  
 
  char thisIsAString[5];
 
  char thisIsAString[5];
  thisIsAString[0]='H';
+
  thisIsAString[0]="H";
  thisIsAString[1]='e';
+
  thisIsAString[1]="e";
  thisIsAString[2]='l';
+
  thisIsAString[2]="l";
  thisIsAString[3]='l';
+
  thisIsAString[3]="l";
  thisIsAString[4]='o';
+
  thisIsAString[4]="o";
  
 
Although it's more commonly seen as
 
Although it's more commonly seen as

Revision as of 21:22, 24 July 2005

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.

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

Although it's more commonly seen as

	char thisIsAString[] = "Hello";

Array members can also be accessed via pointers.

Custom classes can be used in arrays.

Vectors are an alternative to arrays.