如何用cout打印函数指针?
#include <iostream>using namespace std;int foo() {return 0;}int main(){ int (*pf)(); pf = foo; cout << "cout << pf is " << pf << endl; cout << "cout << (void *)pf is " << (void *)pf << endl; printf("printf(\"%%p\", pf) is %p\n", pf); return 0;}
cout<pf为1 cout<(void*)pf为0x100000b0c printf(“%p”,pf)为0x100000b0c。
米琪卡哇伊
侃侃尔雅
相关分类