c++day08

#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;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值