int *p = new int[10];
时间: 2024-05-08 09:17:51 浏览: 12
This code allocates memory on the heap for an integer array of size 10 and assigns the address of the first element to a pointer variable named 'p'. The pointer 'p' can be used to access individual elements of the array or to perform operations on the entire array.
It is important to note that since memory is allocated dynamically using the 'new' keyword, it must be deallocated manually using the 'delete[]' keyword when it is no longer needed. Failure to do so can result in memory leaks.
Here is an example of how to allocate and deallocate memory using the above code:
```c++
int *p = new int[10]; // allocate memory for 10 integers
// use the pointer to access and modify individual elements of the array
p[0] = 1;
p[1] = 2;
// ...
delete[] p; // deallocate memory when finished using it
```