0
点赞
收藏
分享

微信扫一扫

【C 语言练习】结构体的使用

谁知我新 2022-06-21 阅读 67
#include <stdio.h>
typedef struct s1{
int a;
char c;
char s[20]; // 如果要定义 char* s; 记得动态分配空间
};

typedef struct s2{
int a;
char c;
char s[20];
};

int main()
{
struct s1 x;
struct s2* y;
y = (struct s2*)malloc(sizeof(struct s2));



scanf("%d%c%s%d%c%s", &x.a, &x.c, &x.s, &y->a, &y->c, &y->s);

printf("%d %c %s\n", x.a, x.c, x.s);
printf("%d %c %s\n", y->a, y->c, y->s);

return 0;
}

/*

1ajkl
2bxyz
1 a jkl
2 b xyz

Process returned 0 (0x0) execution time : 10.914 s
Press any key to continue.


*/


举报

相关推荐

0 条评论