如何在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 红包祝福语简短10字
18 周六早晨祝福语简短