指针是一个变量,其值是另一个变量或存储块的地址,即存储位置的直接地址。像任何变量或常量一样,必须在使用指针存储任何变量或块地址之前声明一个指针。
Datatype *variable_name
Begin. Define a function show. Declare a variable x of the integer datatype. Print the value of varisble x. Declare a pointer p of the integer datatype. Define p as the pointer to the address of show() function. Initialize value to p pointer. End.
这是C语言中的一个简单示例,用于理解指向函数的指针的概念。
#include void show(int x) { printf("Value of x is %d\n", x); } int main(){ void (*p)(int); // declaring a pointer p = &show; // p is the pointer to the show() (*p)(7); //initializing values. return 0; }
输出结果
Value of x is 7.