2025-02-15
This commit is contained in:
parent
bc7fe2dca2
commit
ebb71861e3
27
2207/C语言/1.结构体/结构体变量复制.c
Normal file
27
2207/C语言/1.结构体/结构体变量复制.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user