如何在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.
热门推荐
4 初八的祝福语简短
10 给女儿祝福语简短精辟
11 离别祝福语简短送同事
12 牛年新年祝福语大全简短
13 工人生日祝福语简短
14 送花祝福语简短十一朵
15 撩妹生日祝福语简短
16 讲课祝福语简短10字
17 律所年会祝福语简短
18 小红书生日祝福语简短