Free Heap block ***modified at ***after it was freed

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void test(void);
void testStruct(void);
void tt(void);

struct tagTest 
{
	int a;
	int b;
};

int main(int argc, char* argv[])
{
	testStruct();
	test();   
	system("pause");
	return 0;
}


void test(void)
{
	char* pBuffer = new char[128];
	strcpy(pBuffer, "hello");
	printf("%p %s\n", pBuffer, pBuffer);
	delete[] pBuffer;
	strcpy(pBuffer, "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
	printf("%p %s\n", pBuffer, pBuffer);
	tt();
}
void tt(void)
{
	printf("I do nothing\n");
}
void testStruct(void)
{
	tagTest* pTest = new tagTest();
	pTest->a = 0x11111111;
	pTest->b = 0x22222222;
	printf("%p %d, %d\n", pTest, pTest->a, pTest->b);
	delete pTest;
	pTest->a = 0x33333333;
	pTest->b = 0x44444444;
	printf("%p %d, %d\n", pTest, pTest->a, pTest->b);
	tt();
}

你可能感兴趣的:(struct,delete,System,include)