A pointer can be declared as a pointer to a function.
int fun1 (char *,int);
Int (*pfun1) (char *,int);
PFUN1 = fun1;
int a = (*PFUN1) ("ABCDEFG", 7); Functions are called through function pointers. You can use a pointer as a parameter to a function. In a function call statement, you can use a pointer expression as an argument.
It is entirely conceivable that there is an object in the code area of the memory, through which the object is passed . A function can run this function. Our function names and function pointers are all pointing to this object. So the following kinds of calls are all legal.
#include <stdio.h>#include<stdlib.h>intFuncChar*R) { intnum =0; while(*s! =' /') {num+= *s; S++; } returnnum;}intMainvoid){ CharStr[] ="ABC"; int(*pfunc) (Char*s); Pfunc=func; //a variety of legitimate callsprintf"%d\n", (*pfunc) (str));//call through object entityprintf"%d\n", (*func) (str));//call through object entityprintf"%d\n", func (str));//called by a pointerprintf"%d\n", Pfunc (str));//called by a pointerSystem ("Pause"); return 0;}
The function fun in this example counts the sum of the ASCII values of each character in a string. As I said earlier, the name of the array is also a pointer. in a function call, when the STR is passed to the parameter s as an argument, the value of STR is actually passed to the address that the s,s points to, but Str and s each occupy their respective storage space. The self-adding 1 operation of S in the function body does not imply that STR is also self-added to the 1 Operation .
Do not hurt the pointer (4)--the relationship between the pointer and the function