#include <cstdlib>
#include <iostream>
using namespace std;
const int N=10;
/**
1.编写的代码是放在文件系统上的
2.编译器去读这个程序,通过编译链接生成二进制可执行程序a.out
3. a/out 创建一个终端下去运行程序,运行程序a.out
1.malloc 申请空间
2.calloc 申请空间并且置0
3.扩容
*/
void f(int n){
if(n==1)return;
int A[N];
cout<<"n:"<<n<<endl;
f(n-1);
}
void test01()
{
// c 函数
int *p1 = (int *)malloc(sizeof(int));
//C++操作符
int *p2 = new int(10);//p2=10
int *p4 = new int[10];
cout<<*p2<<endl;
free(p1);
free(p2);
delete [] p4;
}
/******************************************************/
/*
new delete的意义何在
1.对于内置类型,效果是一样的
2.对于自定义类型就不一样
new 会调用自定义类型的构造函数
*/
void test02()
{
int *p1= new int;
int *p2=(int*)malloc(sizeof(int));
}
/******************************************************/
int main() {
//f(100000000);
test01();
cout<<"chengong"<<endl;
}
c++day08
最新推荐文章于 2024-09-02 23:29:10 发布