当前位置:网站首页>C language learning notes: type definition typedef and declaration external CSDN creation punch in

C language learning notes: type definition typedef and declaration external CSDN creation punch in

2022-07-01 18:39:00 CFXLWT

typedef: The type definition

To put it simply, simplify complex names , Go straight to the case :

tepedef struct data{
 int a;
 char b;
}p;// here p When used later, it is equivalent to struct data
int main {
 p j;// use p To define variables of a data structure 
 j.a=1;// No problem. 
 j.b='b';// All are OK Of 
// In this way, it is equivalent to putting a long struct data  Simplified to p
// Similarly, it can be so :
 tepedef int j;// It means that you can use j To define a int Variable 
 j i=12;// here j Equivalent to int
printf(“%d”,i);//12
 typedef char* m;
  m a;// In the same way 
  a="asd";
  printf("%s",a);// Output asd
}

extern: Statement

extern To declare a variable , The old rule goes directly to the case :

Like in one C There are two in the project C Source file main.c Main.c

among main.c:

int main{
printf("%d",p);/* Here you can see that there is no such variable in the source file , But we can declare in another source file , Then this output can also be established .*/
}

Main.c:

extern int p=1;

In this way main.c You can call p 了

原网站

版权声明
本文为[CFXLWT]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202152227221332.html