如何在C中声明指向函数的指针?
指针是一个变量,其值是另一个变量或存储块的地址,即存储位置的直接地址。像任何变量或常量一样,必须在使用指针存储任何变量或块地址之前声明一个指针。
语法
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.
热门推荐
9 短祝福语简短暖心
10 医政科祝福语简短
11 六一祝福语简短感动女生
12 传统新婚祝福语创意简短
13 结婚多层蛋糕祝福语简短
14 弟弟生日祝福语简短的话
15 早晨好正能量祝福语简短
16 婆婆生日祝福语简短的
17 职场离职文案祝福语简短
18 女生 节日祝福语简短大气