Define pointer variables to point to the SUM function
int on the left: the function that the pointer variable p points to returns data of type int
Right (int, int): The function that the pointer variable p points to has 2 parameters of type int
void sum (intint b) {}int (*p) (intint);p= Sum
(*p) is a fixed notation, which means that the pointer variable p will definitely be pointing to the function
void on the left: pointer variable p points to a function that has no return value
Right (): pointer variable p points to function without formal parameter
The definition of block in the OC is void (^myblock) (parameter) = ^{}
Second, according to the scope of the variable, can be divided into:
1. Local Variables:
1> definition: Variables defined inside a function (block of code) (including formal parameters of a function)
2> scope: Start with the line that defines the variable until the end of the code block
3> life cycle: Allocates storage space from the row that defines the variable, which is recycled when the code block ends
4> does not have a fixed initial value
2. Global variables
1> definition: Variables defined outside the function
2> scope: Starts from the line that defines the variable and continues to the end of the file (can be shared by all subsequent functions)
3> life cycle: When a program starts, it allocates storage space and is destroyed when the program exits.
4> The default initial value is 0
Three, arrays: can only be composed of multiple data of the same type
struct: Can consist of several different types of data
#include <stdio.h>intMain () {//int Ages[3] = {[2] = 10, 11, 27}; //int Ages[3] = {10, 11, 29}; //1. Defining the structure type structPerson {//the 3 variables, which can be referred to as members or attributes of a struct. intAge//Age DoubleHeight//Height Char*name;//name }; //2. Define struct variables according to struct type structPerson p = { -,1.55,"Jack"}; P.age= -; P.name="Rose"; printf ("age=%d, name=%s, height=%f\n", P.age, P.name, p.height); /*wrong wording struct person p2; P2 = {1.67, "Jake"}; */ structPerson P2 = {. Height =1.78,. name="Jim",. age= -}; //p2.age = +; return 0;}
Iv. Completion algorithm: The storage space occupied by the struct must be a multiple of the maximum number of member bytes
voidtest1 () {structStudent {intAge//4 bytes CharA; //Char *name;//8 bytes }; structStudent Stu; //stu.age = 20; //stu.name = "Jack"; //Completion algorithm (alignment algorithm)ints =sizeof(Stu);//s = =
Five, structural attention point
1.3 ways to define struct-body variables
1> define a type before defining a variable (defined separately)
struct Student { intstruct Student stu;
2> defining variables at the same time as defining types
struct Student { intstruct Student stu2;
3> defining a variable at the same time as defining a type (omitting the type name)
struct { int age ;} Stu;
2. Scope of the struct type
1> defined outside the function: globally valid (starting from the line that defines the type, until the end of the file)
2> defined inside a function (code block): locally valid (starting with the line that defines the type, until the end of the code block)
VI. structure Array
structRankrecord {intNo//Sequence 4 intScore;//points 4 Char*name;//Name 8 }; //Alignment Algorithm//can store 3 structure variables, 16 bytes per struct variable /*int No;//ordinal 4 char *name;//name 8 int score;//Points 4*/ structRankrecord records[3] = { {1,"Jack", the}, {2,"Jim", -}, {3,"Jake", -} }; records[0].no =4; //wrong wording//Records[0] = {4, "Rose", 9000};
Vii. 1. The definition of a pointer to a struct
struct student{ intstruct Student *p;
2. Use pointers to access members of the struct body
1> (*p). Member name
2> p-> member name
VIII. Structures and functions
1. If the struct is a function parameter, only the value of all members of the argument struct is assigned to all members of the formal parameter structure, modifying the members of the inner structure of the function does not affect the outside argument structure
2. If a struct pointer is used as a function parameter, the address of the struct is passed to the formal parameter, and the member of the structure inside the function is modified to affect the outside argument structure.
Dark Horse Programmer--c Language Summary------Other data types