简单的C++动态分配数组

#include<iostream>
using namespace std;
int main()
{
    int* m=new int(30);//此处是动态声明 一个指向整数的指针 
    //* m=50;//这句话若生效,输出的是50,现在是失效状态,输出30 
    cout<<"* m:"<<*m<<endl;
    float *floatptr=new float;
    *floatptr=0.5; 
    cout<<"*floatptr:"<<* floatptr<<endl;
    delete m;
    delete floatptr;
    return 0;

}

猜你喜欢

转载自blog.csdn.net/agoodboy1997/article/details/82321327