<>8. function
C A function in a language is a piece of code that can be reused , Used to perform a function independently , It can receive parameters passed by users , It can also not be received . It consists of two parts : Function header and function body .
** Function header :** Include return value types , Function name and formal parameter declaration ;
** Function body :** Compound statement , Variables used only in one function , In principle, it should be declared and used in this function , Note, however, that variables with the same name as formal parameters cannot be declared , Otherwise, the error of variable name conflict will occur .
Code demonstration
#include <stdio.h> int main() { int a = 0; int b = 0; int c= 0; printf(
" Enter two operands :"); scanf("%d %d", &a, &b); c = a+b; printf("sum = %d\n", c); return 0;
} // shortcoming : Repeat the above code every time you add two numbers . If you need to perform complex functions , Write a lot of code repeatedly every time , so much trouble Above code , Write the function as follows : #include
<stdio.h> int Add(int x, int y) { int z = x+y; return z; } int main() { int a= 0
; int b = 0; int c= 0; printf(" Enter two operands :"); scanf("%d %d", &a, &b); c = Add(a, b)
; printf("sum = %d\n", c); return 0; }
// Functions can be used repeatedly , Just call each time Add function , You can complete the addition . The same is true for other complex functions , Call function , You can achieve the effect , Simplified code
<>9. array

(1) array define :
In programming , For convenience , Organize several variables of the same type in an orderly form . The collection of similar data elements arranged in order is called an array .
for example
arr[5]={1,2,3,4,5}; //arr Array size is 5, In turn 1,2,3,4,5
(2) Array subscript

Array subscript from 0 start , Increase in turn 1

(3) Use of arrays
#include <stdio.h> int main() { int i = 0; int arr[5] = {1,2,3,4,5}; for(i=0; i
<5; i++) { printf("%d ", arr[i]); } printf("\n"); return 0; }

<>10. Operator

unary operator
! Logical reverse operation - negative + positive & Take address sizeof Type length of operand ( In bytes ) ~ The binary bit negation of a number -- Front , Postposition -- ++
Front , Postposition ++ * Indirect access operator ( dereference operator ) ( type ) Cast type
Relational operator
> >= < <= != For testing “ Unequal ” == For testing “ equal ”
Logical operator
&& Logic and || Logical or
Conditional Operator
exp1 ? exp2 : exp3
comma expression
exp1, exp2, exp3, …expN
Subscript reference , Function calls and struct members
[] () . ->
<>11. Common keywords

(1) keyword typedef( Type redefinition )
// take unsigned int Rename to uint_32, therefore uint_32 It is also a type name typedef unsigned int uint_32; int
main() { // observation a and b, The types of these two variables are the same unsigned int a = 0; uint_32 b = 0; return 0; }
(2) keyword static
stay C In language :
static Is used to modify variables and functions
a. Modify local variables - It is called static local variable
#include <stdio.h> void test() { //static Modify local variables static int i = 0; i++; printf(
"%d ", i); } int main() { int i = 0; for(i=0; i<10; i++) { test(); } return 0; }

b. Modify global variables - It is called static global variable
int g_val = 2018; int main() { printf("%d\n", g_val); return 0; }

c**. Modifier function - Called static function **
// code 1 //add.c int Add(int x, int y) { return c+y; } //test.c int main() {
printf("%d\n", Add(2, 3)); return 0 } // code 2 //add.c static int Add(int x, int y)
{ return c+y; } //test.c int main() { printf("%d\n", Add(2, 3)); return 0; }
code 1 normal , code 2 Connectivity errors occur during compilation .
conclusion :
A function is static modification , So that this function can only be used in the source file , Cannot be used within other source files .

<>12. #define Define constants and macros
//define Define identifier constants #define MAX 1000 //define Ding Yihong #define ADD(x, y) (x+y) #include
<stdio.h> int main() { int sum = ADD(2, 3);// Will be replaced by (2+3) printf("sum = %d\n", sum)
; sum = 10*ADD(2, 3);// Will be replaced by 10*(2+3) printf("sum = %d\n", sum); return 0; }

<>13. Pointer

(1) Memory
Memory is a particularly important memory in a computer , All programs in a computer run in memory .
So in order to use memory effectively , 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 location of the memory unit
site .
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 , Each byte has an address , The address of the first byte is taken out ( Smaller address ) printf("%p\n", &num); return 0; }
// Print address ,%p The printed address is in the form of

Address storage , Pointer variables need to be defined
int num = 10; int *p;//p Is an integer pointer variable p = #
Use examples of pointers :
#include <stdio.h> int main() { int num = 10; int *p = # *p = 20; return 0;
}
Take shaping pointer as an example , Extend to other types
#include <stdio.h> int main() { char ch = 'w'; char* pc = &ch; *pc = 'q';
printf("%c\n", ch); return 0; } // The output result is q
(2) Size of pointer variable
// 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 ) #include
<stdio.h> int main() { printf("%d\n", sizeof(char *)); printf("%d\n", sizeof(
short *)); printf("%d\n", sizeof(int *)); printf("%d\n", sizeof(double *));
return 0; }
<>14. structural morphology
The 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 inclusion : name + Age + Gender + Student number These items of information .
Here we can only use structure to describe .
for example :
struct Stu { char name[10];// name int age; // Age char sex[5]; // Gender char id[10];
// Student number }

Technology