new int question

Hi everyone,
I don't understand these two line:

int* outcomes=new int [13];
thanks a lot.
OK, the 1st line consists of a declaration of a pointer of size int, and then an allocation of an array of 13 ints. It is exactly the same as this:
int *outcomes;             // Declare a pointer to an int
outcomes = new int[13];    // Set the pointer to point to the first of 13 integers. 

Basically, that is a way of making a variable size of array, due to the normal way (int outcomes[13]) requiring the array size to be a compile-time constant. With this method, you could replace the "13" with a variable of your choice.

The outcomes[6]++ is simply a way of adding one to the 7th element of the array, though in this case that value is undefined to start with.
outcomes[6]++ adds one to the "content" of 7th element


outcome[6]: points to the address of 7th element
so outcome[6]++ points to the address of 8th element?

I'm confused by comparing with this:

int * p
p++ // add one to the address of p
*p++ // add one to the content of address P.

Adds one to the "content" of the 7th element.

This is because outcome[6] is the same as *(outcome + 6).
thanks a lot.
Topic archived. No new replies allowed.