C++结构体可以嵌套吗

C++的结构体其实就是一个没有方法的类,既然他是类那当然可以嵌套了

#include"stdio.h"
#define M 20 
struct xx{
    
    
	int xh;
	char mz[10];
	int nl;
	char jg[20],xb[20];
};//类型 

struct sxb{
    
    //顺序表  顺序表的结构都是一样的 
	struct xx a[M];
	int b;
}sxbb;

void main()
{
    
    
	int j;
	sxbb.b=0;
	for(j=0;j<5;j++)
	{
    
    
		printf("输入第%d个学生的信息:",j+1);
		printf("输入学号:");
		scanf("%d",&sxbb.a[j].xh);
		
		printf("输入名字:");
		scanf("%d",&sxbb.a[j].mz);
		
		printf("输入年龄:");
		scanf("%d",&sxbb.a[j].nl);
		
		printf("输入籍贯:");
		scanf("%d",&sxbb.a[j].jg);
		
		printf("输入性别:");
		scanf("%d",&sxbb.a[j].xb);
		sxbb.b++; 
	} 
} 

猜你喜欢

转载自blog.csdn.net/dudadudadd/article/details/112554299