#include <stdio.h>
int main(int argc,char **argv)
{
/*1.声明名称myabc新的数据类型*/
struct myabc {
char a;
short b;
int c;
};
// 2.定义结构体变量abc
struct myabc abc ;
// 3.初始化结构体变量
abc.a = 77;
abc.b = 88;
abc.c = 99;
//其他写法
/*写法1
struct {
int a;
char b;
float c;
}abc;
abc.a=1;
abc.b='2';
abc.c=3;*/
/*写法2
struct {
int a;
char b;
float c;
}abc={
.a=1,
.b='2',
.c=3,
};*/
/*写法3
struct myabc{
int a;
char b;
float c;
};
struct myabc abc ={
.a = 1,
.b = '2',
.c = 3,
};*/
// 4.调用
printf("a=%d,b=%d,c=%d\n",abc.a,abc.b,abc.c);
/*
printf("size = %d\n",sizeof(struct myabc));
printf("size = %d\n",sizeof(int));
*/
return 0;
}
函数传结构体的值
#include <stdio.h>
struct myabc
{
int a;
int b;
int c;
};
void fun(struct myabc *pabc){
printf("%d\n", pabc->a);
printf("%d\n",pabc);
}
int main(int argc, char const *argv[])
{
struct myabc abc;
abc.a=1;
abc.b=2;
abc.c=3;
// struct myabc abc={1,2,3};
fun(&abc);
return 0;
}