newlist

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

写出函数指针、函数返回指针、const指针、指向const的指针、指向const的const指针

答案:

void (f*)()

void * f()

const int*

int* const

const int* const

 

函数指针的使用

#include<stdio.h>

//这里最好可以使用<cstdio.h>

int max(int x,int y)

{

  return x>y?x:y;

}

int main()

{

  int max(int,int);//这两行代码通常是是关于函数指针调用的,通常用做考点

  int (*p)(int,int)=&max;  

  int a,b,c,d;

  printf("Please input three integer\n");

  scanf("%d%d%d",&a,&b,&c);//这里的双斜杠也要注意

  d=(*p)((*p)(a,b),c);//这里的调用要注意一下

  printf("Among %d,%d,and %d the maxmal integer is %d\n",a,b,c,d);

  return 0;

}

posted on 2011-11-24 20:52  一枚程序  阅读(186)  评论(0编辑  收藏  举报