Help creating class objects

Pages: 12
Syntactically, the name of an array is interchangeable with a pointer to the type of object stored in the array. The value of the pointer is the memory address of the first object in the array. So:

1
2
3
int myArray[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

int i = *myArray;  // Sets i to 0, because myArray can be used as an int* 


And:

1
2
3
4
5
6
7
void myFunction(int* intPtr, int numberOfInts)
{
  for (int j = 0; j < numberOfInts; ++j)
  {
    intPtr[i] = i;  // Can use intPtr as if it was the name of an array
  }
}


Of course, you're usually better off using STL containers rather than arrays.
Topic archived. No new replies allowed.
Pages: 12