2.
#include <iostream>
#include <malloc.h>
#include <stdio.h>
using namespace std;
struct stu
{
int *a;
int *b;
};
int main()
{
//struct stu *s=new stu[10];
//struct stu s=new stu;
struct stu s;
s.a=new int [10];
s.b=new int[10];
//struct stu s;
struct stu s1;//
for (int i=0; i<4; i++)
{
cin>>s.a[i]>>s.b[i];
cout<<s.a[i]<<" "<<s.b[i]<<endl;
}
delete []s;
delete []s.a;
//delete []s.b;
while (1);
return 0;
}
本文详细介绍了C++中使用结构体定义变量,并通过内存分配实现动态内存管理的过程。通过实例展示了如何创建结构体对象并对其进行赋值、输入输出操作,以及如何释放分配的内存资源。
15万+

被折叠的 条评论
为什么被折叠?



