几种主要类别的指针

来源:互联网 发布:淘宝直播运营公司 编辑:程序博客网 时间:2024/05/02 04:30

转载自《程序员面试宝典》

面试题1:写出函数指针、函数返回指针、const指针、指向 const的指针、指向const的const指针。

函数指针如 void (*f) (),如已存在一个int max(int x, int y),那么代码中,函数指针可以这样来用

int a=1, b=2;int (*ptr)(int, int);ptr=max;cout<<(*ptr)(a, b)<<endl;

函数返回指针则如 int* f(),意味着函数返回值是一个整型指针。


const指针,就把const前置,如const int*

指向const指针,就把const后置,如int* const

那么指向const的const指针就是cont int* const.

0 0