因为new也可以使用栈空间#include <iostream>
#include <cstdio>
#include <new>
int main()
{
unsigned char buffer[1024];
int *p = new (buffer)int[10];
std::cout << (void *)buffer << std::endl;
std::cout << (void *)p << std::endl;
for(int i = 0; i < 10; ++i)
p[i] = i;
for(int i = 0; i < sizeof(int) * 10; ++i)
printf("%.2X ", buffer[i]);
std::cout << std::endl;
return 0;
}
00CFF434
00CFF434
00 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00
请按任意键继续. . .
|