例:用new开辟空间存放一个结构体变量,delete运算符撤销所开辟的空间
#include<iostream>
#include<string.h>
using namespace std;
struct Student
{
char name[10];
int num;
char sex;
};
int main(void)
{
Student *p;
p = new Student;
strcpy(p-> name, "Wang Yun");
p-> num = 10123;
p-> sex = 'M';
cout << p-> name << " " << p-> num << " " << p-> sex << endl;
delete p;
return 0;
}