typedef 作用:一般给已经有的变量类型起名字
typedef unsigned int u8;
typedef int arr[10];
struct Student
{
int data;
char name[16];
};
typedef struct Student S;
unsigned int data;
data=10;
typedef unsigned int u8;
u8 data=20;
可值typedef为了 unsigned int类型名,重新命名为u8
一般配合结构体使用,为了方便不需要写struct
struct Student
{
int data;
char name[16];
};
typedef struct Student S;
int main()
{
S s;
s.data=10;
printf("struct data=%d\n",s.data);
}
#include<stdio.h>
#include<stdlib.h>
/*
typedef 给已经有的变量类型起名字,
一般配合结构体使用,为了方便不需要写struct
*/
typedef unsigned int u8;
typedef int arr[10];
struct Student
{
int data;
char name[16];
};
typedef struct Student S;
struct
{
int data;
char name[32];
}demo;
typedef struct
{
int data;
char name[32];
}Demo2;
void print(S s)
{
printf("void function_struct data=%d\n",s.data);
}
int main()
{
u8 data1=100;
printf("int_u8_data1=%d\n",data1);
arr a;
a[0]=1;
printf("arr[10] a[0]=%d\n",a[0]);
S s;
s.data=10;
printf("struct data=%d\n",s.data);
print(s);
demo.data=90;
printf("demo.data=%d\n",demo.data);
Demo2 d;
d.data=16;
printf("Demo2 d.data=%s\n",d.data);
return 0;
}