In order to create a dynamic integer array with a given size SIZE, you do the following:
1 2 3 4 5 6 7 8
#define SIZE 100
...
int *numbers;
numbers = newint[SIZE](); // initialize with values zero
for (unsignedint i = 0; i < SIZE; ++i)
{
numbers[i] = i;
}
This results in a segmentation fault.
However...
1 2 3 4 5 6 7 8
#define SIZE 100
...
int *numbers;
numbers = newint[SIZE](); // initialize with values zero
for (unsignedint i = 0; i < SIZE; ++i)
{
*(&numbers[i]) = i;
}
results in what I want.
But in all the tutorials I've seen around the Internet, you can simply write values by using the [] operator!
Can somebody explain to me what I'm doing wrong?
Thanks