1. Pointer function and function pointer, array of function pointers
Pointer function: A function that returns a value as a pointer
Char *fun () {char str[] = "Hello World"; return str;} int main () {char *p = fun (); Puts (p); return 0;}
at compile time, a warning appears, returning the first address of a memory space that has been freed
workaround: 1, static
Span style= "font-family:"microsoft yahei"; Font-size:18px "> 2, char *str =" Hello World ";
3, malloc Note: Use it to free and set the pointer to null (relative to method two, this is more reasonable!) The STR address is considered to be open without disturbing the normal process)
typedef: Alias an existing type
Span style= "font-family:"microsoft yahei"; font-size:18px ">typedef unsigned int size_t;
unsigned int A;
size_t A;
>>>> malloc
void *malloc (size_t size);
Function: Programmer manually request memory space in the heap area
Parameter: Size: The amount of memory space to request (in bytes)
Return value: Success: The first address of the requested memory space
Failure: NULL----when memory is low
>>>>memset
Span style= "font-family:"microsoft yahei"; font-size:18px ">void * pointer, as a formal parameter, can receive any type of pointer
void *memset (void *s, int c, size_t n);
function: Set the value of the memory space, in bytes
parameter: s---" The first address of the memory space to set
c---"The value to set
n---"size of memory space (bytes)
return value: Set the first address of the memory space
>>>>bzero
void bzero (void *s, size_t n);
Function: Empty a contiguous memory space
Parameter: s---the first address of the memory space that needs to be emptied
N---"Size to Empty
>>>> void free (void *ptr);
Function: Releases the memory space that the PTR points to
>>> function Pointers: pointers to functions
int fun (int a), int (*p) (int) = Fun;fun (Ten);p(10);
Note: The function name is the entry address of the function
This and the array pointers are very similar!
>>> Array of function pointers
is the array, the element of the array is the function pointer, the pointer points to the function
Int (*p[4]) (int, int);
>>> Recursive functions: Call yourself----"unfold
4, the structure---"can be used to describe a specific thing
declaration: struct Structure Body name
{
data type member name 1;
data type member name 2;
.....
};
DECLARE struct: The main thing is to tell the compiler that there is a struct type (strcut struct name), which is usually declared before the main function .
define struct-body variables: strcut structure name variable name;
Access struct member: struct variable name. member name;
>>> struct pointer---pointer to struct-body variable
int *p;
struct struct body name *p = & struct variable name;
access members through struct pointers: pointer variable name, member name;
>>> struct Arrays
struct struct body an array group name [number of elements];
struct Table arr[3];
2, the common body---"size end
feature: All members of a common body use the same memory space together
Shared Memory Size: memory size of the member occupying the largest memory space
Declaration: Union Common body Name
{
data type member name 1;
data type member name 2;
.....
};
define a common body variable: union common body name variable name;
size End---"Storage mode
Big -Endian storage: Low-byte data stored at high addresses, high-byte data stored at low address
Small-End storage: low-byte data stored at low addresses, high-byte data stored at high addresses
3. Enumeration----is generally used as the definition of error code
enum enum name
{
member 1,
member 2,
Members 3
};
Entry Training Note--day9 (1, pointer function and function pointer, array of function pointers 2, malloc memset 3, recursive function 4, struct 5, common body---size end 6, enumeration)