如何在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.
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短