int grid_x = 5
int * grid;
grid = new int[grid_x];
*grid = 34;
cout << grid[0];
Should line 3 create an array with 5 elements? Or fill the first
element with the number 5?
. "new"
4 , ?
[], :
for int (i=0; i < grid_x; i++) {
grid[i] = 0;
}
4 5 "-842150451".
, .
, , 2 x y, , , . .
, . , boost::scoped_array, , .
, , - , scoped_array scoped_arrays. for.
using boost::scoped_array;
int grid_x;
int grid_y;
scoped_array<scoped_array<int> > grid(new scoped_array<int> [grid_x]);
for (int i = 0; i < grid_x; i++)
grid[i] = scoped_array<int>(new int[grid_y] );
grid[x][y];
:
scoped_array ,
typedef int* p_int_t;
p_int_t* grid = new p_int_t [grid_x];
for (int i = 0; i < grid_x; i++)
grid[i] = new int[grid_y];
, .