指针求最大值

来源:互联网 发布:unity3d百度地图映射 编辑:程序博客网 时间:2024/06/07 12:00
/*
    指针练习
*/
#include <stdio.h>
int *max(const int *p_num, int size) {
    const int *p_tmp = NULL,*p_max = NULL;
    for (p_tmp = p_num;p_tmp <= p_num + size - 1;p_tmp++) {
       if (!p_max || *p_max < *p_tmp) {
           p_max = p_tmp;
       }
    }
    return (int *)p_max;
}
int main() {
    int arr[] = {34, 62, 15, 22, 41};
    int *p_num = max(arr, 5);
    printf("最大数字是%d\n", *p_num);
    return 0;
}
原创粉丝点击