首页 > 电脑

结构体类型怎么保存在一个变量

更新时间2019-05-13 09:32:30

#include<stdio.h>

#include<windows.h>

 

struct test

{

int a;

int b;

char c;

char d[20];

};

 

void main()

{

struct test test1= {0};

char copy[20] ={0};

 

  test1.a = 1;

test1.b=2;

test1.c='a';

strcpy(test1.d ,"this is a test");

 

// int a1 =  test1.a;

// int b1 = test1.b;

// char c1 = test1.c;

       strcpy(copy,test1.d);

 

}


//  =====有//的地方请帮忙修正=====

结构体是一种用户自定义的数据类型,其实是一组相关变量的集合。例如,要存放学生的信息,包括学号,姓名,性别,成绩等,就可以用结构体变量。在c语言中定义结构体类型及变量如下。先定义结构体类型struct student{int num;char name[10];char sex;float score;};再用结构体类型定义结构体变量,struct student stu;结构体变量成员的引用。stu.numstu.namestu.sexstu.score

上一篇:C++错误lnk2001什么意思,怎么处理,有时有,有时没有

下一篇:电脑为什么总是自动重启?