结构体的声明、定义、以及结构体变量多种赋值方法学习
#include <stdio.h>#include <string.h>
struct student
{
int num;
float score;
char* name;
}stu1,stu2;
int main(void)
{
stu1.num = 54243;stu1.score = 100.0;
stu2.num = 54244;stu2.score = 99.0;
stu1.name = "Tom";stu2.name = "Bob";
//strcpy(stu1.name , "Tom");strcpy(stu2.name ,"Bob");
printf("stu1.num = %d,stu1.score = %4.1f,stu1.name = %s\n",stu1.num,stu1.score,stu1.name);
printf("stu2.num = %d,stu2.score = %4.1f,stu2.name = %s\n",stu2.num,stu2.score,stu2.name);
return 0;
}
页:
[1]