C language IV, typedef keyword, and scope one, typedef keywords
In the C language, there is a typedef keyword, the function of which is to allow you to define a new name for the type, that is, the individual name
For example:
int DWORD
So later, when we define a variable of type unsigned int, this does not have to write unsigned int. Direct DWORD.
For example:
DWORD name = 0;
Usually used in the definition of struct, and function pointer.
For example:
typedef struct mystruct{ int A; int b; } Myintstruct;
Then the new type is myintstruct, and this type eliminates the keyword when you define it every time.
For example:
int main{ //struct mystruct is; Not defined before, to use the above myintstruct is ; IS.A = ten; return 0; }
Ii. Scope
In the C language, the code you write has scope limitations.
What is the scope?
In short, when we define variables, this variable is accessed. To be accessible within a certain region.
For example, if you define variable a in the A function, and the B function defines the variable B, then the B function cannot use the A variable.
For example:
#include <stdio.h>void printfb () { intone; printf ("%d\r\n", b); } void PRINTFA () { int; printf ("%d\r\n", a);}
The above is the function scope, that is, the {} block statement contains.
Code block scope:
The scope of a block of code is largely differentiated by {}.
For example:
int main () { int a = ten; { int a = one; printf ("%d", a); Block statement bracketing } printf ("%d", a); return 0;}
If this is defined, then a is not redefined. and a = 11, after the code executes to the end. No longer exists.
File scope:
The file scope is defined outside the code. In other words, global variables. Global scope, which can be accessed at any location in the current file.
For example:
int a = ten; Outside the declaration can be. int main () { printf ("%d", a); return 0;}
C language IV, typedef keyword, and scope