new delete
Posted roadmap
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了new delete相关的知识,希望对你有一定的参考价值。
#include <stdio.h>
#include "stdafx.h"
struct Person {
public:
int age;
Person()
{
this->age = 0;
}
Person(int age);
};
Person::Person(int age)
{
this->age = age;
}
int main(int argc, char* argv[])
{
int *i = new int;
printf("*i: %d\n", *i);
delete i;
int *j = new int(5);
printf("*j: %d\n", *j);
delete j;
int *k = new int[5];
k[0] = 0;
k[1] = 1;
delete[] k;
Person *p = new Person;
printf("p->age: %d\n", p->age);
delete p;
Person *p1 = new Person(30);
printf("p1->age: %d\n", p1->age);
delete p1;
getchar();
return 0;
}
以上是关于new delete的主要内容,如果未能解决你的问题,请参考以下文章