c++申请内存空间的本质

c++申请内存空间的本质

void teseTwo()
{
	char cc[8];
	cout << (void*)cc << endl;
	cout << "将cc的内存空间存储字符串" << endl;
	strcpy_s(cc, "hello");
	cout <<"cc= " << cc << endl;
	cout << "将cc的内存空间存储整数" << endl;
	int* a;
	int* b;
	a = (int*)cc;
	b = (int*)cc + 4;
	*a = 10;
	*b = 22;
	cout << *((int*)cc) << endl;
	cout << *((int*)cc+4) << endl;
	cout << "将cc的内容用于double" << endl;
	double* d = (double*)cc;
	*d = 1.11;
	cout << *((double*)cc) << endl;
	cout << "将cc的内容用于结构体" << endl;
	struct stt
	{
		int a;
		char b[4];
	}*st;
	st = (struct stt*)cc;
	st->a = 23;
	strcpy_s(st->b, "aaa");
	cout << st->a << endl;
	cout << st->b << endl;

	cout << "malloc函数本质也是一堆空间" << endl;
	int* cc1 = (int*)malloc(8);
	*cc1 = 11;
	cout << *cc1 << endl;

}

c++申请内存空间的本质_第1张图片

你可能感兴趣的:(C++11简单的使用方法,c++,开发语言)