C++ 允许传递指针给函数,只需要声明函数参数为指针类型即可。
程序示例:
#include <iostream>
#include <ctime>
using namespace std;
// 函数声明
void getSeconds(unsigned long *par);
int main ()
{
unsigned long sec;
getSeconds( &sec );
cout << "seconds time is :" << sec << endl;
return 0;
}
// 函数实体,参数为指针
void getSeconds(unsigned long *par)
{
*par = time( NULL );
cout << "the time is :" << *par << endl;
return;
}
输出结果: