如何在 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.
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP