两种方式new动态内存

# cat 126.cpp
#include <iostream>
using namespace std;

int main()
{
  //int* points_age = new int;     //method 1
  int* points_age;
  points_age = new int;              //method 2

  cout << "enter your dog's age:" ;
  cin >> *points_age;

  cout << "age " << *points_age << " is stored at " << points_age << endl;

  delete points_age;



  return 0;
}

  

# ./a.out
enter your dog's age:30
age 30 is stored at 0xe8f010

  

posted on 2019-08-15 12:29  cdekelon  阅读(96)  评论(0)    收藏  举报

导航