From ebb71861e3d5e0abd8bcfcc4dc508409bacfca93 Mon Sep 17 00:00:00 2001 From: smallkun Date: Sat, 15 Feb 2025 01:58:06 +0800 Subject: [PATCH] 2025-02-15 --- 2207/C语言/1.结构体/结构体变量复制.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2207/C语言/1.结构体/结构体变量复制.c diff --git a/2207/C语言/1.结构体/结构体变量复制.c b/2207/C语言/1.结构体/结构体变量复制.c new file mode 100644 index 0000000..281fe42 --- /dev/null +++ b/2207/C语言/1.结构体/结构体变量复制.c @@ -0,0 +1,27 @@ +#include +#include + +typedef struct Node{ + int id; + char name[20]; +} student; + +//! 结构体变量的复制 基本数据类型可以复制 数组都可以复制 而不是 只复制数组的地址 +int main(void){ + + student s1, s2; + s1.id = 1; + strcpy(s1.name, "LH"); + + s2 = s1; + printf("s1:%d %s\n", s1.id, s1.name); + printf("s2:%d %s\n", s2.id, s2.name); + + s2.name[0] = 'A'; + + printf("s1:%d %s\n", s1.id, s1.name); + printf("s2:%d %s\n", s2.id, s2.name); + + + return 0; +} \ No newline at end of file