|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <string.h>
struct student
{
int num;
float score;
char* name;
};
int main(void)
{
struct student stu1,stu2;
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;
}
|
|