1, function pointer
As the name implies, pointers to functions are the same as other pointers, which hold the address of the pointer to the function.
If the void type function pointer can be defined in either void (*f) (parameter list) or typedef void (*f) (argument list),
F. But be aware that the type of the function pointer is the same as the function type.
Here's a simple example
1#include <stdio.h>2#include <stdlib.h>3typedefvoid(*F) (); 4 5 voidPrint_hello ()//simple definition of a non-parametric print function6 {7printf"Hello ~\n");8 }9 Ten voidMain () One { AF F1;//This is equivalent to void (*F1) (); - void(*F2) (); - theF1 =Print_hello; -F2 =Print_hello; - - F1 (); + F2 (); - +System"Pause"); A}
View Code
2, pointer function
A pointer function is a function that returns a value as a pointer. For example int *a (), char *b () ... A function that represents the return value as a shape pointer, a character pointer, respectively.
Here's a simple example
#include <stdio.h>#include<stdlib.h>Char*str ()//defines a function that returns a character pointer{ Char*a ="Hello World ~"; returnA;}voidMain () {Char*c = str ();//You can assign values at the same time as defined Char(By//can also be defined first, after assignmentb =str (); printf ("%s\n%s\n", c,b); System ("Pause");}
View Code
C language about pointer function and function pointer personal understanding