结合体哪里有问题
程序代码:#include<stdio.h>
typedef struct{
int a;
char b;
}yang;
int main(){
struct yang str1,*str2;
str1.a=3;
str1->a=5;
str2.a=9;
str2->b='hun';
printf("%d,%d,%d,%c",str1,str2);
return 0;
}
程序代码:#include<stdio.h>
#include<stdlib.h>
typedef struct{
int a;
char b;
}yang;
int main(){
yang str1,*str2;//已经typedef了,就直接yang做类型名号了
str1.a=3;
str1.b='c';//'.'点表示结构体成员运算,而str1在定义时已经分配了空间,所以a和b直接赋值
str2=(yang *)malloc(sizeof(yang));//str2是指针,没有分配空间,所以要malloc,你明白的
str2->a=9;
str2->b='h';//箭头是指向结构体成员运算符,指向明白吧,用于指针喽,链表中必备的运算符
printf("%d,%d,%c,%c",str1.a,str2->a,str1.b,str2->b);//这里要针对结构体的各节点分别输出,可不能输出结构体名啊,没意义的
return 0;
}
就这样

