//C++������new�������ڶ�����������
//�������ٵ����ݣ��ɳ���Ա�ֶ����٣��ֶ��ͷţ��ͷ����ò����� delete
//�﷨ ��new ��������
//����new���������ݣ��᷵�ظ����ݶ�Ӧ�����͵�ָ��

//ʵ�� 1���������﷨

#include <iostream>

//1��new�Ļ����﷨
int* func()
{
	//�ڶ���������������
	//new���ص���  ���������͵�ָ��
	int * p = new int(10);

	return p;

}



void test01()
{
	int* p = func();

	std::cout << *p << std::endl;
	std::cout << *p << std::endl;
	std::cout << *p << std::endl;

	//����������  �ɳ���Ա���٣�����Ա�����ͷ�
	//������ͷŶ��������ݣ����ùؼ��� delete

	delete p;

	//std::cout << *p << std::endl;   //�ڴ��Ѿ����ͷ� �ٴη��ʾ��ǷǷ�����


}


//2���ڶ�������new��������
void test02()
{
	//����10�����ε����飬�ڶ���
	int* arr = new int[10];    //10����������ʮ��Ԫ��

	for (int i = 0; i < 10; i++)
	{
		
		arr[i] = i + 100;      //��10��Ԫ�ظ�ֵ  100 ��109

	}

	for (int i = 0; i < 10; i++)
	{

		std::cout << arr[i] << std::endl;

	}

	//�ͷŶ�������

	//�ͷŶ��������ʱ��  Ҫ�� []  �ſ���
	delete[] arr;

}



int main()
{
	test01();
	test02();

	system("pause");

	return 0;

}