Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C language data structure linked list content, this application node space, let P point to the first address formula, can someone explain the meaning to me, can't you understand it?
C language data structure linked list content, this application node space, let P point to the first address formula, can someone explain the meaning to me, can't you understand it?
1 and sizeof (type name or variable name) are used to calculate the size of a type or variable, in bytes. For example:

Structure s

{

char c;

char arr[2];

};

s s 1;

float f = 1. 1;

sizeof(float)=4,sizeof(f)= 4;

//sizeof(struct S) is the total size of all members of the calculation type struct S, that is, Sizeof (c)+Sizeof (arr) =1+2 = 3.

sizeof(struct S)= 3;

//Because the size of a variable is equal to the size of its type, sizeof (s1) = sizeof (structures) = 3.

sizeof(s 1)= 3;

2.malloc is a library function. Malloc (size); The function of is to allocate a memory of size in the heap, and then return the first address of this memory block, but it returns a void* pointer, so it is necessary to type the return value. For example:

int * pint =(int *)malloc(sizeof(int));

//Suppose the first address is 100, and the heap memory addresses that pointer ps can use are 100,10, 102 (because sizeof(struct S)=3, malloc allocates 3 bytes of memory).

//and ps points to the first address 100.

struct S * PS =(struct S *)malloc(sizeof(struct S));

3. Memory allocated with malloc must be released with free (pointer variable name), which is another library function. For example:

//release the above structure through structures * PS = (structures *) malloc (size of (structures)); 3 bytes of memory allocated by the statement.

Free (PS);

Understand the above three points, your code is not difficult to understand.