<> catalogue

* Common keywords
1.1 keyword typedef
1.2 keyword static
* #define Define constants and macros
* Pointer
3.1 Memory
3.2 Size of pointer variable
* structural morphology
<>1. Common keywords

keyword –C Built in to the language itself , Keywords are not created by yourself , Can't be created .C Languages in total 32 Keywords , According to different functions , It can be divided into the following four categories :

* Data type keyword (12 individual )
(1)char: Declare a character variable or function (1 byte )
(2)short: Declaring short variables and functions (2 byte )
(3)int: Declare an integer variable or function (2/4 byte )
(4)long: Declare a long variable or function (4/8 byte )
(5)float: Declare a floating-point variable or function (4 byte )
(6)double: Declare a double variable or function (8 byte )
(7)signed: Declare a variable or function of signed type
(8)unsigned: Declaring an unsigned type variable or function
(9)void: Declare that the function has no return value or no parameters , Declaring a typeless pointer
(10)enum: Declaring enumeration types
(11)struct: Declare structure variables
(12)union: Declare community ( union ) data type
* Control statement keywords (12 individual )
Loop statement
(1)for: A circular statement
(2)do: Loop body of a loop statement
(3)while : Loop condition of loop statement
(4)break: Jump out of current cycle
(5)continue: End current cycle , Start next cycle
Conditional statement
(6)if: Conditional statement
(7)else: Conditional statement negative branch ( And if Combined use )
(8)goto: Unconditional jump statement
Switch statement
(9)switch : For switch statements
(10)case: Switch statement branch
(11)default: In switch statements “ other ” branch
Return statement
(12)return: Subroutine return statement ( Can take parameters , Or without parameters )
* Storage type keyword (4 individual )
(1)auto: Declare automatic variables
(2)extern: Declare global variables
(3)register: Declare register variables
(4)static: Declare static variables
* Other function keywords (4 individual )
(1)const: Declare read-only variables
(2)sizeof: Calculate storage space
(3)typedef: Alias data type
(4)volatile: Explain that variables can be changed implicitly during program execution
among auto( Automatic variable ) Are often ignored keywords
(auto) int a=10;// Automatic variable ,auto Ignored
<>1.1 keyword typedef

typedef As the name suggests, it is a type definition , This should be understood as type rename .typedef Type only .
#include<stdio.h> // take unsigned int Rename to uint_32, therefore uint_32 Is also a type name typedef
unsigned int uint_32; int main() { // observation num1 and num2, These two variables are of the same type unsigned int num1
= 0; uint_32 num2 = 0; printf("%d %d",num1,num2); return 0; }

<>1.2 keyword static

stay C In language :static Is used to modify variables and functions

* Decorate local variables - Called static local variables
* Decorate global variables - Called static global variables
* Decorating function - Called static function
<>static Decorate local variables

a. Local variables in functions :
Claim period extension : This variable does not end with the end of the function
initialization : Initialize only the first time the function is called
Memory : During subsequent call , This variable uses the value saved after the previous function call is completed
Storage location : Not stored in stack area , Put in data segment
for example : nothing static Decorated local variable
```bash ```bash ```c #include<stdio.h> void test() { int a=1; a++; printf("%d"
,a); } int main() { int i=0; while(i<10) { test(); i++; } return 0; }

have static Decorated local variable :
#include<stdio.h> void test() { static int a=1; a++; printf("%d",a); } int main
() { int i=0; while(i<10) { test(); i++; } return 0; }

You can see no static Decorate local variables a time , The output is 10 individual 2, have static Decorate local variables a When , The output is 2 reach 11. that is because static When decorating local variables , Local variable scope , Not destroyed , In essence static Decorate local variables , By changing the storage location of variables from stack area to static area , It also makes the life cycle of the variable longer , Make its life cycle the same as the program life cycle .

<>static Decorate global variables

Global variables have external link attributes ( compile + link = Executable program )
static When modifying global variables , The external link attribute of a global variable becomes an internal link attribute . Other source files (.c) You can no longer use this global variable .( Scope becomes smaller )
for example : No, static When modifying global variables

have static When modifying global variables

<>static Decorating function

Functions also have external link properties , cover static Decoration time , External link properties become internal link properties , Other source files (.c) This function can no longer be used .
for example , No, static When decorating a function :

have static When decorating a function :

<>2.define Define constants and macros
//define Define identifier constants #define MAX 1000 //define Definitional macro #define ADD(x, y) ((x)+(y))
// among Add Is macro ,x and y Is an argument to a macro , Parameter is untyped , among ((x)+(y)) Is a macro #include <stdio.h> int main() { int
sum= ADD(2, 3); printf("sum = %d\n", sum); sum = 10*ADD(2, 3); printf("sum =
%d\n", sum); return 0; }
Explain in detail later .

<>3. Pointer

Pointer is the address of program data in memory , Pointer variables are variables used to store these addresses .

<>3.1 Memory

Memory is a particularly important memory in a computer , All programs in the computer run in memory . So in order to use memory effectively , Just divide the memory into small memory units , The size of each memory unit is 1 Bytes . In order to effectively access each unit of memory , The memory unit is numbered , These numbers are called the address of the memory unit . for example :

For example, every room in a residential building has a number , You can quickly query the corresponding rooms through these numbers .

In the above figure 0x00AFFDF0 Yes storage a Address of , Also apply to memory 4 First address in bytes , among & Is the address operator
Variables are created in memory ( To allocate space in memory ), Each memory cell has an address , So variables also have addresses . Take out the variable address as follows :
#include <stdio.h> int main() { int num = 10; #// take out num Address of
// notes : here num of 4 Bytes , Every byte has an address , The address of the first byte is taken out ( Smaller address ) printf("%p\n", &num);
// Print address ,%p Is printed as an address return 0; }

here 0053FD9C yes num Address of .
Memory unit : number –》 address –》 Addresses are also called pointers
How to store the address , Pointer variable needs to be defined . Store pointer ( address ) A variable of is a pointer variable
int num = 10; int *p;//p Is an integer pointer variable p = #
* explain p Is a pointer variable ,int explain p( Pointer variable ) The object pointed to is int Type

*p Is a dereference operator , Is through p Address stored in , find p Object referred to , among *p yes p Object pointed to by .
#include <stdio.h> int main() { int num = 10; int *p = # *p = 20; return 0;
<> Size of pointer variable
#include <stdio.h> // The size of the pointer variable depends on the size of the address //32 The address under the bit platform is 32 individual bit position ( Namely 4 Bytes )
//64 The address under the bit platform is 64 individual bit position ( Namely 8 Bytes ) int main() { printf("%d\n", sizeof(char *)); printf(
"%d\n", sizeof(short *)); printf("%d\n", sizeof(int *)); printf("%d\n", sizeof(
double *)); return 0; }

This is 32 Pointer size under address of bit machine .

This is in 64 Pointer size under address of bit machine . Explain in detail later

<> structural morphology

Structure is C Especially important knowledge points in language , Structure makes C Language has the ability to describe complex types .
For example, describe students , Student includes : name + Age + Gender + Student ID information .
Only structure can be used here to describe . for example :
struct Stu {// member char name[20];// name int age; // Age char sex[5]; // Gender char id[15]
;// Student ID }; // Print structure information struct Stu s = {" Zhang San ", 20, " male ", "20180101"}; //. Accessing operators for structure members
printf("name = %s age = %d sex = %s id = %s\n", s.name, s.age, s.sex, s.id);
// Structure object . member name //-> Operator struct Stu *ps = &s; printf("name = %s age = %d sex = %s id
= %s\n", ps->name, ps->age, ps->sex, ps->id);// Structure pointer variable --> member name

Explain in detail later .

<> summary

I learned a lot today , In particular, the structure is C Important knowledge points in language , The pointer is again C Difficulties in language , These knowledge points will be unveiled in Xiaomu's articles in the future . If there is any deficiency in the above , Please correct me , thank you .

©2019-2020 Toolsou All rights reserved,
evo Tool usage problems ——Degenerate covariance rank, Umeyama alignment is not possible Experiment 4 Automated test tools - software test mysql Export data sql sentence _mysql according to sql Query statement export data Create a thread ——— Javaweb (3) Data structure experiment ( three )—— Stacks and queues TS stay vue2 Writing in the project web Front end signature plug-in _signature_pad Plug in implements electronic signature function docker Where is the image stored Qt Getting Started tutorial 【 Basic controls 】QCalendarWidget calendar control springboot How to get reality in ip address