结构体赋值

 2023-09-05 阅读 38 评论 0

摘要:#include <stdio.h>struct student{int ID;char name[48];int age; }; int main(){struct student s1 = { 1, "lifei", 24 };struct student s2;s2 = s1;//s2.name = "letben";//错误 1 error C2106: “=”: 左操作数必须为左值 f:\tr
#include <stdio.h>struct student{int ID;char name[48];int age;
};
int main(){struct student s1 = { 1, "lifei", 24 };struct student s2;s2 = s1;//s2.name = "letben";//错误    1    error C2106: “=”: 左操作数必须为左值    f:\tryc++\结构体的赋值\结构体的赋值\main.c    15    1    结构体的赋值//所以在底层我们的结构赋值语句中关于字符数组的操作被改写成了字符串拷贝命令。strcpy(s2.name, "letben");s2.ID = 2;s2.age = 25;printf("s2的基本信息:学号:%d,姓名:%s,年龄:%d", s2.ID, s2.name, s2.age);getchar();return 0;
}

 

转载于:https://www.cnblogs.com/letben/p/5240360.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/1224.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息