指针高级应用

 1 // 6_9.cpp : 定义控制台应用程序的入口点。
 2 //
 3 
 4 #include "stdafx.h"
 5 #include<stdio.h>
 6 #include<stdlib.h>
 7 
 8 
 9 float *show(int a,float (*arr1)[4])//指针函数
10 {
11     /*float *pt=NULL;
12     pt=*(arr1+a);*/
13     return *(arr1+a);
14 };
15 int Max(int a,int b)
16 {
17     return a>b?a:b;
18 };
19 int Min(int a,int b)
20 {
21     return a<b?a:b;
22 };
23 int Func(int a,int b,int (*p)(int,int))//函数指针
24 {
25     return (*p)(a,b);
26 };
27 int _tmain(int argc, _TCHAR* argv[])
28 {
29     //指针数组
30     char *p[4]={"I","am","a","boy"};
31     int i;
32     for(i=0;i<4;i++)
33         printf("%s  ",p[i]);
34     puts("\n");
35     //数组指针
36     char arr[4]={'L','O','V','E'};
37     char (*p2)[4]=&arr;
38     for(i=0;i<4;++i)
39         printf("%c ",(*p2)[i]);
40     puts("\n");
41     //指针函数
42     static float fScore[][4]={{11,22,33,44},
43     {12,23,34,45},{77,88,99,99.5},{1.5,2.5,3.5,4.5}};
44     int n;
45     float *pp;
46     scanf("%d",&n);
47     pp=show(n-1,fScore);
48     for(i=0;i<4;++i)
49         printf("%0.2f  ",*(pp+i));
50     //函数指针
51     puts("\n");
52     printf("max=%d\n",Func(1,2,Max));
53     printf("min=%d",Func(1,2,Min));//调用函数,函数名即为该地址
54     system("pause");
55     return 0;
56 }

 

posted @ 2017-04-22 14:16  gd_沐辰  阅读(211)  评论(0编辑  收藏  举报