函数名,函数名取地址,函数名取值之间的区别
来源:互联网 发布:sql数据库管理下载 编辑:程序博客网 时间:2024/06/05 18:04
#include <stdio.h>typedef void (*cfp_t)(int a);cfp_t calls_table[3]={NULL,};void test(int a){ printf("test();\n");}int main(void){ printf("************0**********\n"); printf("test:%d\n",test); printf("&test:%d\n",&test); printf("*test:%d\n",*test); printf("************1**********\n"); calls_table[0]=test; calls_table[0](5); printf("main();\n"); printf("************2**********\n"); calls_table[0]=&test; calls_table[0](5); printf("main();\n"); printf("************3**********\n"); calls_table[0]=*test; calls_table[0](5); printf("main();\n"); printf("************4**********\n"); calls_table[0]=test; (*calls_table[0])(5); printf("main();\n"); printf("************5**********\n"); calls_table[0]=&test; (*calls_table[0])(5);//执行 printf("main();\n"); printf("************6**********\n"); (&test)(5); printf("************7**********\n"); (*test)(5);}
输出结果:
************0**********
test:4195709
&test:4195709
*test:4195709
************1**********
test();
main();
************2**********
test();
main();
************3**********
test();
main();
************4**********
test();
main();
************5**********
test();
main();
************6**********
test();
************7**********
test();
/usercode/file.cpp: In function ‘int main()’:
/usercode/file.cpp:16:30: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘void (*)(int)’ [-Wformat=]
printf("test:%d\n",test);
^
/usercode/file.cpp:17:32: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘void (*)(int)’ [-Wformat=]
printf("&test:%d\n",&test);
^
/usercode/file.cpp:18:32: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘void (*)(int)’ [-Wformat=]
printf("*test:%d\n",*test);
^
由输出结果:可知,函数名,函数名取地址,函数名取值之间可以随意替换。不像数组名,数组名取地址,数组名取值那样区别很大。
- 函数名,函数名取地址,函数名取值之间的区别
- 函数名&函数名取地址
- 数组名取地址 函数名取地址
- 函数名地址、函数名取地址、函数名解引用问题
- 数组名、数组名取地址以及作为函数传递带来的问题
- 函数名、数组名实际上是地址与地址的真正区别
- 函数名/函数地址/函数指针
- c++函数名地址验证
- c++函数名地址验证
- 函数名之标号地址
- 如何通过函数名获取虚函数的地址?
- 函数/函数名的本质
- 函数名和数组名最大的区别
- 变量名、函数名
- 函数名
- 函数名前后加const的区别
- js函数名和带()的区别
- 函数名的理解
- Solidworks小技巧
- jsp中计算时间(年月日 时分秒)
- LeetCode 648. Replace Words 字典树练习
- portaudio使用笔记
- recompiled header file is from a previous version of the compiler, or the precompiled header is C++
- 函数名,函数名取地址,函数名取值之间的区别
- 使用asList 不能进行add(),remove()操作,如何解决?
- 第一章:1.2.3 LTI系统研究方法与本章小结
- openstack storlets 文档(一)
- 数字转汉字算法
- 学会制作柱形图,一眼区分工作效率差异
- MySQL创建用户与授权方法
- 141. Linked List Cycle
- 特征处理实践