Dynamic Memory Allocation: header file stdlib. h
Malloc: Memory Allocation
Calloc: allocates memory and clears it.
Realloc: adjust the size of allocated memory blocks
Demo:
Int * P = (int *) malloc (3 * sizeof (INT); // allocates memory. The first address is returned successfully, and the first address is returned if no value is returned.
Free (p); P = NULL; // release the allocated memory and change the pointer value to avoid the occurrence of a wild pointer (pointing to an address, but the address has been recycled)
Const and pointer:
Const int * P; // the pointer is variable, and the corresponding data of the pointer cannot be changed.
Int * const P; // the pointer is unchangeable and the corresponding data of the pointer can be changed.
Const int * const P; // the pointer is unchangeable and the corresponding data of the pointer cannot be changed.
Pointer to the function:
Int add (int A, int B) {return a + B ;}
Int MUL (int A, int B) {return a * B ;}
INT (* A) (INT, INT) = NULL; // defines the function type pointer.
Int sum;
A = add;
Sum = A (3, 4); // 7
A = Mul;
Sum = A (3, 4); // 12
Typedef int (* pA) (INT, INT) pa1, pa2; // defines the function type pointer.
Pa1 = add;
Pa2 = Mul;
Sum = pa1 (3, 4); // 7
Sum = pa2 (3, 4); // 12
Variable-length sequence: header file stdarg. h
Int max (INT count,...) // count indicates the number of distinct numbers.
{
Va_list V;
Va_start (v, count );
For (INT I = 0; I <count; I ++)
{
Int argi = va_arg (v, INT); // retrieve the values of each vertex
}
Va_end (v );
}
C programming notes day06 dynamic memory allocation, function pointer, variable length limit